Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

Test the Speed of 2 programs

Thread view: 
IveCal - 28 Sep 2006 02:59 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/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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.