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

How Fast is Your Java Code

on

  • 756 views

 

Statistics

Views

Total Views
756
Views on SlideShare
723
Embed Views
33

Actions

Likes
0
Downloads
5
Comments
0

2 Embeds 33

http://www.jug.lv 31
http://jug.lv 2

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    How Fast is Your Java Code How Fast is Your Java Code Presentation Transcript

    • How Fast is Your Java Code? Performance micro-benchmarking Dmitry Buzdin
    • About Speaker buzdin@gmail.com @buzdinDmitry Buzdin
    • Motivation
    • Programming for Performance
    • SituationSome developers optimize code a lotGood habits like:* Putting final keyword* Optimizing assignments* Creating less objects* Avoiding reflection
    • SituationArguing who’s code is faster
    • So how do youmeasure that?
    • Macro-benchmarking vs Micro-benchmarking
    • Challenge
    • Challenge: How Fast is That?System.out.println("Hello, World!");
    • DEMO
    • 1 millisecond = 1 000 microseconds =1 000 000 nanoseconds
    • Test NoiseClassloader activitiesReflection inflationGarbage collectionJIT compilation
    • JIT CompilerBehavior-drivenCan compile and “de-compile”Client and Ser ver JITs are different
    • Getting JVM StatsManagementFactory.getXYZBean()
    • ClassLoadingMXBeanGarbageCollectorMXBeanRuntimeMXBeanMemoryMXBeanThreadMXBean...
    • Measurement PitfallsMeasuring in millisecondsNot doing warm-upsNot doing enough warm-upsWrong JVM settingsToo few iterations
    • Conclusions
    • ConclusionsDo not do micro optimizationsWrite first - then measure criticalplacesProgram readability is more importantDo perform macro optimizationsinstead
    • “We should forget about small efficiencies, say about 97% of thetime: premature optimization is the root of all evil” Donald Knuth
    • 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
    • Code is on GitHubhttps://github.com/buzdin/java-microbenchmarking/
    • The End