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.
Go to menu Run | Run ... to open up the Run Dialog Window. Add the time command to show the runtime in the console.
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.
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.
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".
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With