Re: How Do You Tell How Long it Takes for a Piece of Code to Execute?
- From: "Mike Schilling" <mscottschilling@xxxxxxxxxxx>
- Date: Tue, 18 Jul 2006 00:21:41 GMT
<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");
}
}
.
- References:
- Prev by Date: Re: How Do You Tell How Long it Takes for a Piece of Code to Execute?
- Next by Date: Re: inner class and static
- Previous by thread: Re: How Do You Tell How Long it Takes for a Piece of Code to Execute?
- Next by thread: Re: How Do You Tell How Long it Takes for a Piece of Code to Execute?
- Index(es):
Relevant Pages
|