I have a program which i have myself written in java, but I want to test method execution times and get timings for specific methods. I was wondering if this is possible, by maybe somehow an eclipse plug-in? or maybe inserting some code?
I see, it is quite a small program, nothing more than 1500 lines, which would be better a dedicated tool or System.currentTimeMillis()
?
JMH is short for Java Microbenchmark Harness. JMH is a toolkit that helps you implement Java microbenchmarks correctly. JMH is developed by the same people who implement the Java virtual machine, so these guys know what they are doing.
Other than using a profiler, a simple way of getting what you want is the following:
public class SomeClass{ public void somePublicMethod() { long startTime = System.currentTimeMillis(); someMethodWhichYouWantToProfile(); long endTime = System.currentTimeMillis(); System.out.println("Total execution time: " + (endTime-startTime) + "ms"); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With