Re: How Do You Tell How Long it Takes for a Piece of Code to Execute?



<kvnsmnsn@xxxxxxxxxxx> wrote:
I've been looking at classes <Time>, <Date>, and <Calendar>, trying to
figure out how to time how long it takes my program to execute, but
without any luck. What I want to do is store a time value at the be-
ginning of my program, and then store a time value at the end of my
program, and then at the end of my program subtract the two values and
come up with how many milliseconds passed while the program was exe-
cuting.
So far OK.

For a bit I thought I could simply call the <getTime()> method of
class <Date> twice to accomplish this, since that method is supposed
to give the number of milliseconds transpired since 1 January 1970,
OK, but even simpler would be calling System.currentTimeMillis() twice and
subtracting the two values.

but no matter how long it takes for my program to run when I subtract
the two values I always get zero.
Where in your code did you get the end-time of your program?
You should do it just before you call System.exit(). This is *not*
necessarily equivalent to doing it at the end of your main method.
Consider a typical GUI-application. The following example would be *wrong*:
public static long startTime = System.currentTimeMillis();
public static void main(String args[]) {
showGUI();
System.out.println((System.currentTimeMillis() - startTime) + "
millisec");
}
It would print "0 millisec" or little more, because showGUI() immediately
returns after the GUI has popped up. But the GUI may run further for hours,
until the user exits the application.

Does anyone know what I can do to time my Java program? Any informa-
tion anyone can give me would be greatly appreciated.
--
Thomas


.



Relevant Pages

  • Re: Where do the information go? GUI(GUIDE) question
    ... It's likely you read it in your newsreader and marked it as read, ... cellsm structures and such in the workspace. ... Where do the GUI fetch its info?. ... There are some ways to store data in your GUI that you can use. ...
    (comp.soft-sys.matlab)
  • Re: OnClick Handler
    ... definately something wrong with storing the same thing twice if you have no good to do so. ... to store the same thing twice. ... Again with the tautology. ... your inflated sense of the importance of the reasons you've stated causes you to describe them as "fairly significant". ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Store.exe Version
    ... > by the store. ... Whereas changing the values in the gui, ... > quota values, because i thought this would more closely ... >>limits and use the IS defaults. ...
    (microsoft.public.exchange2000.information.store)
  • Re: storing password in variable
    ... > i'm prompted for a password (twice) each time openssl is invoked. ... > store the password in a variable, and use it each time openssl is invoked ... > throughout the script. ...
    (comp.unix.shell)
  • Re: Migration of Teradata and DB2 Timestamp fields.
    ... There is no datatype in SQL Server that has a precision of 1 millisecond. ... - Store the timestamp in a CHARcolumn in format ... Note that the precision will go back to 3.33 milliseconds when you ...
    (microsoft.public.sqlserver.datawarehouse)