Microbenchmarking with JMH

Uploaded on

Microbenchmark basic and lesson about being suspicious about benchmark. The source code is here: https://github.com/henri-tremblay/microbenchmarkingwithjmh

Microbenchmark basic and lesson about being suspicious about benchmark. The source code is here: https://github.com/henri-tremblay/microbenchmarkingwithjmh

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads


Total Views
On Slideshare
From Embeds
Number of Embeds



Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide
  • Démo du Main.Class loading time taken into accountJVM optimizations not applied yetOptimization plan impact between benchmarksCode elimination
  • Codé par des experts travaillantsur le JDKUtilisé pour tester les performances de Java 8, par exemple
  • Saufquebiensûr, c’est pas magique.Ilvousdonne les outils pour réussirvos benchmarks maisilfautquandmême les utilisercorrectement
  • Le code n’est pas exécutémaisutilisé pour générer le benchmark. Plein de protection contre les tours quepourraitvousjouer la JVM. Çaressemble à ça. Évidemment, je n’ai pas la prétention de pouvoirtousvous les expliquer. False sharing, etc
  • Démo du Main.
  • 79%
  • Démo du Main.
  • Qu’est-cequ’on en conclue de tout ça?
  • Démo du Main.


  • 1. 1 Tél : +33 (0)1 58 56 10 00 Fax : +33 (0)1 58 56 10 01 www.octo.com© OCTO 2014 50, avenue des Champs-Elysées 75008 Paris - FRANCE Microbenchmarking with JMH
  • 2. 2 Henri Tremblay OCTO Technology Senior Architect R&D manager Performance specialist EasyMock lead developer Objenesis lead developer
  • 3. 3 WHAT IS IT?
  • 4. 4 JAPEX
  • 5. 5
  • 6. 6 Hotspot optimizations compiler tactics delayed compilation tiered compilation on-stack replacement delayed reoptimization program dependence graph representation static single assignment representation speculative (profile-based) techniques optimistic nullness assertions optimistic type assertions optimistic type strengthening optimistic array length strengthening untaken branch pruning optimistic N-morphic inlining branch frequency prediction call frequency prediction proof-based techniques exact type inference memory value inference memory value tracking constant folding reassociation operator strength reduction null check elimination type test strength reduction type test elimination algebraic simplification common subexpression elimination integer range typing flow-sensitive rewrites conditional constant propagation dominating test detection flow-carried type narrowing dead code elimination language-specific techniques class hierarchy analysis devirtualization symbolic constant propagation autobox elimination escape analysis lock elision lock fusion de-reflection memory and placement transformation expression hoisting expression sinking redundant store elimination adjacent store fusion card-mark elimination merge-point splitting loop transformations loop unrolling loop peeling safepoint elimination iteration range splitting range check elimination loop vectorization global code shaping inlining (graph integration) global code motion heat-based code layout switch balancing throw inlining control flow graph transformation local code scheduling local code bundling delay slot filling graph-coloring register allocation linear scan register allocation live range splitting copy coalescing constant splitting copy removal address mode matching instruction peepholing DFA-based code generator
  • 7. 7 vs
  • 8. 8 CODE
  • 9. 9 JMH = Java Microbenchmarking Harness
  • 10. 10
  • 11. 11 http://hg.openjdk.java.net/code-tools/jmh/file/tip/jmh-samples/src/main/java/org/openjdk/jmh/samples/ JMHSample_01_HelloWorld.java JMHSample_02_BenchmarkModes.java JMHSample_03_States.java JMHSample_04_DefaultState.java JMHSample_05_StateFixtures.java JMHSample_06_FixtureLevel.java JMHSample_07_FixtureLevelInvocation.java JMHSample_08_DeadCode.java JMHSample_09_Blackholes.java JMHSample_10_ConstantFold.java JMHSample_11_Loops.java JMHSample_12_Forking.java JMHSample_13_RunToRun.java JMHSample_15_Asymmetric.java JMHSample_16_CompilerControl.java JMHSample_17_SyncIterations.java JMHSample_18_Control.java JMHSample_20_Annotations.java JMHSample_21_ConsumeCPU.java JMHSample_22_FalseSharing.java JMHSample_23_AuxCounters.java JMHSample_24_Inheritance.java JMHSample_25_API_GA.java JMHSample_26_BatchSize.java JMHSample_27_Params.java
  • 12. 12 HOW DOES IT WORK?
  • 13. 13 CODE
  • 14. 14 Intel Core i7-4500U 1.8 GHz (to 2.5 GHz with Intel Turbo Boost) 1 800 000 000 cycles per second 3 600 000 000 instructions per second (approx.) Our baseline: 2 849 277 267 empty method calls per second Not bad!
  • 15. 15 CODE
  • 16. 16
  • 17. 17 @Setup / @TearDown BlackHole @Group / @GroupThreads @CompilerControl(CompilerControl.Mode.DONT_INLINE) BlackHole.consumeCPU … Other features
  • 18. 18 CODE
  • 19. 19
  • 20. 20
  • 21. 21
  • 22. 22 EasyMock Mockito Interface mocking 167 ns/op 4080 ns/op Class mocking 8588 ns/op 4273 ns/op
  • 23. 23 Bottomline I need to investigate a bit You need to be cautious! and be suspicious of any benchmark you read Examples: • HikariCP • NodeJS vs J2EE (http://blog.octo.com/en/the-art-of-benchmarking/)
  • 24. 24 http://perfug.github.io / +Henri Tremblay @henri_tremblay htremblay@octo.com http://brownbaglunch.fr