21

How can I see how much time it took for the code to run in InteliJ?

1 Answer 1

24

I don't think you can with Intellij, you either have to use a profiler like Yourkit to profile the code or use some primitive benchmarks using System.currentTimeInMillis(). Alternatively you can use Apache Commons StopWatch to do some benchmarking:

StopWatch stopwatch = new StopWatch();
stopwatch.start();
... some code...
stopwatch.stop();
long timeTaken = stopWatch.getTime()

https://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/time/StopWatch.html

EDIT: There is a plugin available for Intellij that uses VisualVM to do profiling, you could install this as another alternative.

http://plugins.intellij.net/plugin/?id=3749

4
  • Thanks, the VisualVM plugin does the job. Also, it seems that YourKit is a shareware that even for the "free evolution" requires registration, just an FYI for future readers.
    – Eran
    Jul 31, 2009 at 1:16
  • 3
    "free evolution" - one of the funniest spelling mistakes :)
    – ripper234
    Jul 31, 2009 at 7:11
  • Hehe, opps! Happens when you don't think enough about what it is you're writing, but just let it come out automatically, or maybe it was just getting too late and close to sleeping time.
    – Eran
    Jul 31, 2009 at 7:50
  • 2
    please correct stopWatch to stopwatch to be consistent (better naming convention would be Camel probably, though)
    – ben26941
    May 28, 2019 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.