Bug 61040 - Add a time shifting function
Summary: Add a time shifting function
Status: RESOLVED FIXED
Alias: None
Product: JMeter
Classification: Unclassified
Component: Main (show other bugs)
Version: Nightly (Please specify date)
Hardware: PC All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: JMeter issues mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-04-25 13:32 UTC by mchassagneux
Modified: 2017-09-17 13:01 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mchassagneux 2017-04-25 13:32:54 UTC
Add a new function to jmeter to shift date easily

See : https://github.com/apache/jmeter/pull/291
Comment 1 Philippe Mouawad 2017-05-01 15:45:28 UTC
Hi Maxime,
I think your code can be committed now.
Regards
Comment 2 mchassagneux 2017-05-02 11:54:09 UTC
I always hesitate to the implementation for the duration to add. 
Either I use the regex and implement our own format ( with months, days, minutes, seconds and even more like weeks etc..)  or I use the Java 8 implementation with Duration object.

I made a micro bench like this : 

Collection<CompoundVariable> params = makeParams("YYYY-MM-dd'T'HH:mm:ss", "", "P10DT-1H-5M5S", "");
long start = System.nanoTime();
for (int i = 0; i < 100_000; i++) {
	function.setParameters(params);
	value = function.execute(result, null);
}
long elapsed = System.nanoTime() - start;
params = makeParams("YYYY-MM-dd'T'HH:mm:ss", "", "+10d-1H-5m5s", "");
start = System.nanoTime();
for (int i = 0; i < 100_000; i++) {
	function2.setParameters(params);
	value = function2.execute(result, null);
}
long elapsed2 = System.nanoTime() - start;
System.out.println("Duration implementation : " + elapsed + " nanosecond");
System.out.println("Regex implementation : " + elapsed2 + " nanosecond");	

With 100_000 calls result are :

Duration implementation : 536599024 nanosecond
Regex implementation    : 283168954 nanosecond

With 1_000_000 calls :

Duration implementation  : 1915462780 nanosecond
Regex implementation     : 1687908387 nanosecond

With 10_000_000 calls :

Duration implementation  : 16609113426 nanosecond
Regex implementation     : 16680832427 nanosecond


With 100_000_000 calls :
Duration implementation  : 150074506145 nanosecond
Regex implementation     : 164859380430 nanosecond

So about 10_000_000 calls, the Duration implementation start to be better in performance.

For me, I prefere the Regex implementation, which is more flexible and easy to understand for a user.

What is your opinion?
Comment 3 Vladimir Sitnikov 2017-05-02 12:38:10 UTC
>What is your opinion?

Please use JMH for benchmarks. Thank you.
Comment 4 mchassagneux 2017-05-09 09:50:58 UTC
Close with commit r1794517 : http://svn.apache.org/viewvc?rev=1794517&view=rev
Comment 5 Milamber 2017-09-17 13:01:45 UTC
URL: http://svn.apache.org/viewvc?rev=1794517&view=rev
Log:
Add a time shifting function
Bugzilla Id: 61040

Added:
    jmeter/trunk/licenses/bin/hamcrest-date-2.0.4.txt
    jmeter/trunk/src/functions/org/apache/jmeter/functions/TimeShift.java
    jmeter/trunk/test/src/org/apache/jmeter/functions/TestTimeShiftFunction.java
Modified:
    jmeter/trunk/LICENSE
    jmeter/trunk/build.properties
    jmeter/trunk/build.xml
    jmeter/trunk/eclipse.classpath
    jmeter/trunk/res/maven/ApacheJMeter_parent.pom
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
    jmeter/trunk/test/src/org/apache/jmeter/functions/FunctionTestHelper.java
    jmeter/trunk/xdocs/changes.xml
    jmeter/trunk/xdocs/usermanual/functions.xml