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




<kvnsmnsn@xxxxxxxxxxx> wrote in message
news:1153178286.175283.205760@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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.

Sure; use System.currentTimeMillis(), e.g

public class Timeit
{
public static void main(String[] args)
{
long start = System.currentTimeMillis();
for (int i = 0; i < 10000000; i++)
{
new Object();
}
long end = System.currentTimeMillis();
System.out.println(end-start + " milliseconds");
}
}




.



Relevant Pages

  • How Do You Tell How Long it Takes for a Piece of Code to Execute?
    ... figure out how to time how long it takes my program to execute, ... without any luck. ... What I want to do is store a time value at the be- ... and then at the end of my program subtract the two values and ...
    (comp.lang.java.programmer)
  • Re: How Do You Tell How Long it Takes for a Piece of Code to Execute?
    ... figure out how to time how long it takes my program to execute, ... without any luck. ... What I want to do is store a time value at the be- ... and then at the end of my program subtract the two values and ...
    (comp.lang.java.programmer)
  • Re: Best way to store postfix data?
    ... with control logic in the same time as the old read one line, execute ... but there's some memory hog I've missed in there. ... that seems infinitely preferable to trying to store them inline ... Since I allow control routines, I have to execute at runtime, ...
    (microsoft.public.vc.mfc)
  • Re: is malloc thread-safe??
    ... Richard Tobin wrote: ... If two separate threads that share the variable both execute the ... it can do the "store", the second thread can load, add, and store, ... C on some systems), an implementation-dependent locking mechanism ...
    (comp.lang.c)
  • Re: Control Source/Record Source issue
    ... unbound text box to pull the correct NTG. ... TEST.NTG and be able to revise and store it in Subfunctions.NTG I ... have tried pulling it in as default but no luck. ... The form is based on a query that includes both values, ...
    (microsoft.public.access.formscoding)