Hello... I have 2 progs, A and B. I want to know which of the 2 runs
faster. I just cant use Date to display the when the progs start and
end because I want to see the difference in milliseconds/nanoseconds.
Can somebody help me? Please... Thanks.
Andrew Thompson - 28 Sep 2006 03:40 GMT
> Hello... I have 2 progs, A and B. I want to know which of the 2 runs
> faster. I just cant use Date to display the when the progs start and
> end because I want to see the difference in milliseconds/ ...
java.util.Date.Date() (JavaDocs for no-args constructor)
"Allocates a Date object and initializes it so that it represents
the time at which it was allocated, measured to the
*nearest* *millisecond*...."
( though if you do not want to deal with objects, see..
java.lang.System.currentTimeMillis() )
Andrew T.
Manish Pandit - 28 Sep 2006 03:49 GMT
System.currentTimeMillis() or if you are using JDK 1.5
System.nanoTime()
-cheers,
Manish
jmcgill - 02 Oct 2006 05:20 GMT
> Hello... I have 2 progs, A and B. I want to know which of the 2 runs
> faster.
You should realize that a java routine, depending on the runtime
environment, can have enormously different performance if it is run
several times in a long-running process, versus just running once. Some
of the JRE's are pretty smart about this sort of thing.
And if you stick I/O code in to just print a time stamp, it's quite
likely that most of the time represented there will be due to the I/O
itself.
Profiling can give far more useful information than just a timestamp of
a particular run. Consider using a Profiler. JProbe has a freeware
version that does a fine job on local stuff. There are lots of others;
some free, some with specialized applications, some commercial, most
with some sort of trial version.