Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Avoiding Benchmarking Pitfalls on the JVM (BBL 2014-09-12)

Julien Ponge
September 12, 2014

Avoiding Benchmarking Pitfalls on the JVM (BBL 2014-09-12)

Slides supporting a BBL talk that I recently did on the topic of benchmarking on the JVM. People don't expect benchmarking to be that tricky to get right.

Julien Ponge

September 12, 2014
Tweet

More Decks by Julien Ponge

Other Decks in Programming

Transcript

  1. @jponge ! Maître de Conférences INSA/Telecom ! CITI-INRIA Laboratory DynaMid

    team Associate Director (industry) ! Golo, IzPack, Maven Mojo, GlassFish, Devoxx, etc ! Oracle Java Magazine
  2. package main ! import ( "fmt" "time" ) ! func

    Fib(n int64) int64 { if (n <= 2) { return n } else { return Fib(n - 1) + Fib(n - 2) } } ! func main() { for i := 0; i < 10; i++ { start := time.Now() Fib(44) fmt.Println(time.Since(start)) } } 4.738337584s 4.477160663s 4.408593662s 4.398906292s 4.533431874s 4.57529716s 4.519544937s 4.673349279s 4.945866449s 4.886524219s “Looks ok”
  3. object FibApp extends App { ! def fib(n: Long): Long

    = if (n <= 2) n else fib(n - 1) + fib(n - 2) ! def howfast[T](block: => T): T = { val start = System.currentTimeMillis() val res = block println((System.currentTimeMillis() - start) + "ms") res } ! for (i <- 1 to 10) { howfast { fib(44) } } } 2787ms 3068ms 2857ms 2832ms 2797ms 2797ms 2839ms 2778ms 2896ms 2752ms “Looks ok”
  4. Dynamic compilation Guess tricks during execution (Java, Scala, JavaScript/V8, etc)

    ! ! Hybrid interpreter + JIT (HotSpot) “Just JIT” (V8, JRockit)
  5. static double distance(double x1, double y1, double x2, double y2)

    { double dx = x2 - x1; double dy = y2 - y1; return Math.sqrt((dx * dx) + (dy * dy)); } How fast?
  6. Dead-code elimination Constant folding Loop unrolling On-stack replacement Inlining Locks

    removal (…) https://wiki.openjdk.java.net/display/HotSpot/PerformanceTechniques
  7. “JMH is a Java harness for building, running, and analysing

    nano/micro/milli/ macro benchmarks written in Java and other languages targeting the JVM.”
  8. JMH is great, but: ! • doubt • peer review

    • beware HotSpot • results don’t compose • read all Aleksey’s samples