Profile the elapsed time in Java

Aslam Anver
2 min readJan 14, 2020


Everything matters when it delivered on time, so why not the same rule applies for your programming unless you are developing a system for turtles.

Getting the execution time of a bunch of methods together in one line will not give you an accurate time. You can execute each method in Java runnable class to measure the elapsed time of each and every method with the identification name.

The below method is a demonstration of getting elapsed time of “myMethod()” by executing the method inside a runnable interface into “ProfileTime.exec()” static method.

Copy the ProfileTime class into your project and start profiling your application right now.

Run the method inside the profiler

Have you done it already? I mean push-ups if not start it from today.

The output is (I mean this program) ;)

Console output of the program

Like to review the code? You can check it in my Gist.

That’s all you can now profile the time of your methods and save much time.

Enjoy your coffee :)

Thank me later.

I’m Aslam Anver find me on GitHub and StackOverflow as aslamanver & Googlian



Aslam Anver

Passionate in AI Deep Learning, Find me on GitHub & StackOverflow