Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

Outline

Sample to show hot methods in a Java Flight Recording

This program checks whether a given random number is primitive or not.

Run the program and also make a profiling recording.

How to run

java -Xms64m -Xmx64m -XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=settings=profile,duration=60s,name=Hotmethods,filename=hotmethods.jfr -XX:FlightRecorderOptions=loglevel=info -jar target/hotmethods.jar

Analyzing Java Flight Recording

In Code -> Hot Methods tab, you should see that the program has spent a lot of time in the LinkedList.indexOf(Object) method, which is called from contains method.

Improving Performance

By changing LinkedList to a HashSet, you can make the program run a lot faster.

The contains methods in Linked List checks all the items. Algorithm run time is O(n). However the HashSet contains algorithm's run time is O(1).

In the program, change Collection<Integer> primeNumbers = new LinkedList<>() to Collection<Integer> primeNumbers = new HashSet<>() to use a HashSet for Prime Numbers

Check the runtime using HashSet.

Use time command in Linux to measure the time.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.