How to Override Response Time in JMeter Reports

Yashwant Raju
2 min readJan 3, 2025

--

JMeter, by default, calculates the sample time as the total elapsed time from request initiation to response completion. However, in scenarios where network latency or SSL overhead is irrelevant, you might want to focus solely on the server-side execution time provided in the API response.

Imagine your API response payload contains the execution time as {"timetaken": "25"}. Here’s how you can override JMeter's sample time with this value:

The Hack
We can make JMeter use this timetaken as the sample time, ensuring your reports tell the real story. Here’s how:

  1. Extract the Execution Time
    Add a JSON Extractor to your test plan, configured with the JSON path $.timetaken. Save it to a variable like responseElapsedTime.
  2. Override JMeter’s Sample Time
    Add a JSR223 PostProcessor and drop in this Groovy script:
var responseElapsedTime=vars.get("responseElapsedTime");
def myVarAsLong = Long.parseLong(myVar);
org.apache.commons.lang3.reflect.FieldUtils.writeField(prev, "timetaken", myVarAsLong, true);

This script tweaks JMeter’s internal sample time to use the timetaken value from your response.

Why This Matters
This hack is a game-changer for scenarios where external factors (like network latency) muddy the waters. By focusing on server-side execution time:

  • You get cleaner insights. It’s all about your backend’s efficiency.
  • You isolate the variables. Perfect for debugging and benchmarking.
  • You impress stakeholders. Your reports now reflect the performance improvements where they matter most.

When to Use This
This trick shines in:

  • Microservices testing, where API execution time is king.
  • Internal benchmarks, where external latency is irrelevant.
  • Server-side optimizations, to measure real improvements.
Photo by takahiro taguchi on Unsplash

--

--

No responses yet