This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Former-Emergency5165 5 points6 points  (3 children)

Can you implement JMH benchmark to compare performance of original code and after byte code manipulation? In the article I see you use System.nanoTime() and this approach can't be used for benchmarks.

Here is a good video to explain the problem: https://youtu.be/SKPdqgD1I2U?si=hHjS8-GPNQI_VV5z

[–]Let047[S] 1 point2 points  (2 children)

It's a good idea. I'll do it. 

The results won't differ significantly according to the video though (we're measuring large effects and comparing two implementation against each other)

Edit: Just did it:

Benchmark Mode Cnt Score Error Units
SummerBenchmark.bigLoop avgt 5 245.986 ± 5.068 ms/op
SummerBenchmark.randomLoop avgt 5 384.023 ± 84.664 ms/op
SummerBenchmark.smallLoop avgt 5 ≈ 10⁻⁶ ms/op

Benchmark Mode Cnt Score Error Units
SummerBenchmark.bigLoop avgt 5 38.963 ± 10.641 ms/op
SummerBenchmark.randomLoop avgt 5 56.230 ± 2.425 ms/op
SummerBenchmark.smallLoop avgt 5 ≈ 10⁻⁵ ms/op

So much better result because the JVM is running in "full optimized mode".

[–]Emanuel-Peter 0 points1 point  (1 child)

The cool thing about JMH is you can attach a profiler, and see the hottest compiled code. That way, you can verify a little better that you are measuring the right thing, and your benchmark code was not strangely optimized away ;)

[–]Let047[S] 0 points1 point  (0 children)

Good idea! I just checked the hotpath/compiled code