Can Visual VM detect which block of the code is taking most of the processing time?

I am trying to find out which part of the code of a method is taking the longest time to run.

The familiar way is to using System.nanotime or millisecond but can we do the same with java profiler like Visual VM?


Yes. Visual VM can do that. I will suggest to keep eye on the “self time” and “invocation count” of costly method(s). You will get hint where code is spending time.

Also please keep in mind that while you turn on profiler, your code will run little bit slower than usual as profiler is collecting data.

enter image description here