Test the Speed of 2 programs

I

IveCal

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.
 
A

Andrew Thompson

IveCal said:
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.
 
M

Manish Pandit

System.currentTimeMillis() or if you are using JDK 1.5
System.nanoTime()

-cheers,
Manish
 
J

jmcgill

IveCal said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,281
Latest member
Pedroaciny

Latest Threads

Top