Search code examples
jmeterbeanshell

If it possible to get average response time to variable in JMeter?


Obviously, I know that I have response time in .jtl file and in listener called Aggregate report, but I'm looking for way to get reponse time of request to variable.


Solution

  • You can do it as follows:

    1. Add Beanshell PostProcessor as a child of the request
    2. Put the following code into PostProcessor's "Script" area:

      vars.put("responseTime", String.valueOf(prev.getTime()));
      

    It will get elapsed time for the sampler (in milliseconds) and store it into ${responseTime} variable. You can add sampler label as prefix or postfix to distinguish response times for different samplers.

    prev is a shorthand for parent SampleResult instance.

    See How to Use BeanShell: JMeter's Favorite Built-in Component for comprehensive information on Beanshell scripting in JMeter tests.