Reputation: 2887
I have been reading about JMH. But I couldn't find a way to generate plots using this. Does JMH support plotting? Or are there third party libraries for this purpose?
Upvotes: 4
Views: 2058
Reputation: 18847
JMH does not support plotting. You can write out the performance results into a file (e.g. with -rf csv
or -rf json
), and use whatever plotting tool you are familiar with. Or, you can extract the performance data from RunResult
instance you got from Java API, and parse/render it with any embedded library.
If you use settings to observe single call executions time (or batch calls) and you want to see plot of each durations (something like last plot here), you can combine settings:
@Measurement(batchSize = 1000, iterations = 500)
@BenchmarkMode({Mode.SingleShotTime})
And a bit of scripting to get desired data in csv. In settings like this, there is only summary data in resulting csv from jmh.
mvn package && java -jar target/benchmarks.jar -foe true -rf csv | tee output.txt
N=5 # set here number of benchmarks plus 2
grep Iteration -A 3 output.txt | grep -v Warmup | sed 's/$/,/' | xargs -l$N | sed 's/,$//'
It will output something like:
Iteration 1: 93.915 ±(99.9%) 2066.879 s/op, readerA: 28.487 s/op, readerB: 28.525 s/op, writer: 224.735 s/op, --
Iteration 2: 100.483 ±(99.9%) 1265.993 s/op, readerA: 59.927 s/op, readerB: 60.912 s/op, writer: 180.610 s/op, --
Iteration 3: 76.458 ±(99.9%) 760.395 s/op, readerA: 52.513 s/op, readerB: 52.276 s/op, writer: 124.586 s/op, --
Iteration 4: 84.046 ±(99.9%) 1189.029 s/op, readerA: 46.112 s/op, readerB: 46.724 s/op, writer: 159.303 s/op, --
Upvotes: 4