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
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.