Results 1 to 7 of 7
Thread: time to execute a java app
- 06-22-2010, 08:05 PM #1
Member
- Join Date
- Jun 2010
- Posts
- 2
- Rep Power
- 0
- 06-22-2010, 09:00 PM #2
Do you want to include any overhead caused by eclipse?
Do you want to include the time to load the JVM?
What kind of app is it?
- 06-22-2010, 09:00 PM #3
Not sure what your asking.
You could call System.getNanoTime() and assign it to some long variable at startup,
then when the program is closing
System.out.println (System.getNanoTime() - startTime);
would give you the run time in nanoseconds (approximately).
Why is it important?
- 06-22-2010, 09:02 PM #4
Apologies, it should be "System.nanoTime();"
- 06-23-2010, 04:21 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 06-23-2010, 04:53 AM #6
Member
- Join Date
- Jun 2010
- Posts
- 2
- Rep Power
- 0
Hi,
I just wanted to calculate the time taken to execute a piece of code.So i guess System.nanoTime() would work.
Thanks for all of you.
- 06-23-2010, 08:06 AM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
You are going to be bitten by the JIT compiler if you don't pay any attention; at first a piece of code is interpreted until the HotSpot mechanism hits: then it is going to be compiled and real machine code is running. Allow your code to 'warm up' and only then set your timers; if you want to time, say, a method P(), do this:
The second loop takes the average runtime just to stabilize the measurements.Java Code:// allow the HotSpot mechanism to do it's deeds for (int i= 0; i < 100000; i++) P(); long start= System.nanoTime(); for (int i= 0; i < 100000; i++) P(); long t= (System.nanoTime()-start)/100000;
kind regards,
Jos
Similar Threads
-
JAVA Programmers Wanted - Full-Time and Part-Time Positions open
By javatrek2020 in forum Jobs OfferedReplies: 3Last Post: 08-23-2011, 12:46 PM -
is there a way to tell how to execute a java program in the jar
By aaroncarpet in forum Advanced JavaReplies: 9Last Post: 11-19-2009, 04:31 PM -
Execute external program from java
By ankitmcgill in forum New To JavaReplies: 1Last Post: 06-01-2009, 03:58 AM -
how to execute an executable using java
By kala143 in forum Java 2DReplies: 4Last Post: 09-26-2008, 03:10 PM -
Execute a new program in java
By mathias in forum Advanced JavaReplies: 1Last Post: 07-31-2007, 05:42 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks