Reputation: 21
I have a HTTP request , which will start at time , this value am storing in string variable beforetime String beforetime=${__time(,)}; Before Time ----> 1611822129009 This transaction will be saved in database with modified_date as 2021-01-28 13:08:30.923 I am extracting time from modified_date as below String CurrentTime1=${__groovy(${__groovy(Date.parse('yyyy-MM-dd hh:mm:ss.SSS','${Modified_date_1}').getTime(),)},)} ;
Now current time is --->1611822133322 the difference between this two is difference ---->4313
Upvotes: 0
Views: 713
Reputation: 168157
Given you have:
${before_time)
with the value of 1611822129009
${modified_date)
with the value of 1611822133322
You can calculate the difference and store it into another JMeter Variable using any suitable JSR223 Test Element and the following Groovy code:
def before = vars.get('before_time') as long
def after = vars.get('modified_date') as long
log.info('Before: ' + before)
log.info('After: ' + after)
def difference = after - before
log.info('Difference: ' + difference)
vars.put('difference', difference as String)
The above code subtracts before_time
from the modified_date
and stores the result into difference
JMeter Variable
Now you can add the next line to user.properties file (lives in "bin" folder of your JMeter installation)
sample_variables=difference
and next time you run JMeter in command-line non-GUI mode the .jtl results file will contain the ${difference}
variable value for each sampler. You can even plot the value as a custom chart in the HTML Reporting Dashboard
More information:
Upvotes: 1