Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse to get program execution time

OS:WinXP

Under UNIX-like environment, we can get execution time by $time ./my_program. I wonder we can get execution time info in Eclipse? Is it possible to do this without a profiler? Thanks.

like image 774
Stan Avatar asked Jun 27 '10 06:06

Stan


People also ask

How to see the execution time in Eclipse?

Go to menu Run | Run ... to open up the Run Dialog Window. Add the time command to show the runtime in the console.

How to get Java execution time?

There are two ways to measure elapsed execution time in Java either by using System. currentTimeinMillis()or by using System. nanoTime(). These two methods can be used to measure elapsed or execution time between two method calls or events in Java.

How do you check how long a program has been running Java?

currentTimeMillis(); long elapsedTime = end - start; In the example above, we're using the “System. currentTimeMillis()” static method. The method returns a long value, which refers to the number of milliseconds since January 1st, 1970, in UTC.

How do I know if a program is running in Eclipse?

You can do that by opening the "Open Run Dialog" ("Run" menu), then select your type of application and add in the "Arguments" tab a -DrunInEclipse=true . In your Java code, you can check the value of the property: String inEclipseStr = System. getProperty("runInEclipse"); boolean inEclipse = "true".


1 Answers

It looks like the TPTP Eclipse plugin has this feature: http://www.eclipse.org/tptp/

You could get an approximation of it by the difference of timestamps:

  public static void main(String[] args) throws IOException {

    long start = System.currentTimeMillis();;
    new MyApplication();
    long end = System.currentTimeMillis();;

    System.out.println((end - start) + " ms");
  }

This will print the runtime in ms.

like image 107
Alexis Avatar answered Oct 06 '22 00:10

Alexis