How Fast is Your Java Code
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share
  • 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

Views

Total Views
834
On Slideshare
798
From Embeds
36
Number of Embeds
3

Actions

Shares
Downloads
5
Comments
0
Likes
0

Embeds 36

http://www.jug.lv 31
https://www.linkedin.com 3
http://jug.lv 2

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. How Fast is Your Java Code? Performance micro-benchmarking Dmitry Buzdin
  • 2. About Speaker buzdin@gmail.com @buzdinDmitry Buzdin
  • 3. Motivation
  • 4. Programming for Performance
  • 5. SituationSome developers optimize code a lotGood habits like:* Putting final keyword* Optimizing assignments* Creating less objects* Avoiding reflection
  • 6. SituationArguing who’s code is faster
  • 7. So how do youmeasure that?
  • 8. Macro-benchmarking vs Micro-benchmarking
  • 9. Challenge
  • 10. Challenge: How Fast is That?System.out.println("Hello, World!");
  • 11. DEMO
  • 12. 1 millisecond = 1 000 microseconds =1 000 000 nanoseconds
  • 13. Test NoiseClassloader activitiesReflection inflationGarbage collectionJIT compilation
  • 14. JIT CompilerBehavior-drivenCan compile and “de-compile”Client and Ser ver JITs are different
  • 15. Getting JVM StatsManagementFactory.getXYZBean()
  • 16. ClassLoadingMXBeanGarbageCollectorMXBeanRuntimeMXBeanMemoryMXBeanThreadMXBean...
  • 17. Measurement PitfallsMeasuring in millisecondsNot doing warm-upsNot doing enough warm-upsWrong JVM settingsToo few iterations
  • 18. Conclusions
  • 19. ConclusionsDo not do micro optimizationsWrite first - then measure criticalplacesProgram readability is more importantDo perform macro optimizationsinstead
  • 20. “We should forget about small efficiencies, say about 97% of thetime: premature optimization is the root of all evil” Donald Knuth
  • 21. Some Resources http://www.ibm.com/developer works/java/library/j-benchmark2/ index.htmlhttp://stackoverflow.com/questions/504103/how-do-i-write-a-correct- micro-benchmark-in-java http://docs.oracle.com/javase/specs/ jvms/se7 /html/index.html
  • 22. Code is on GitHubhttps://github.com/buzdin/java-microbenchmarking/
  • 23. The End