Generate project template:
mvn archetype:generate
-DinteractiveMode=false
-DarchetypeGroupId=org.openjdk.jmh
-DarchetypeArtifactId=jmh-java-benchmark-archetype
-DgroupId=com.phonepe.mustang
-DartifactId=benchmarking
-Dversion=1.0.0-SNAPSHOT
Add @Benchmark
for such functions that need to be benchmarked. For more details ref : https://github.com/openjdk/jmh
Build the maven project. And run benchmarks.jar artefact.
java -jar benchmarks.jar
java -jar benchmarks.jar MustangSearchBenchmark
Attach agent of a profiler of your choice and initiate the execution
java -agentpath:/<path-to-async-profiler-2.6-macos>/build/libasyncProfiler.so=start,event=cpu,file=profile.html -jar benchmarks.jar
java -agentpath:/Applications/YourKit-Java-Profiler-2021.11.app/Contents/Resources/bin/mac/libyjpagent.dylib=delay=10000,listen=all -jar benchmarks.jar