Results 1 to 3 of 3
Thread: System Clock
- 04-12-2011, 03:00 PM #1
System Clock
I am running 2 sorting algorithms (Merge and Insertion) on a series of integer arrays. My assignment is to run the algorithms and do an analysis on the efficiency of each one. I am supposed to use the system clock to time the algorithms, but for some reason, no measurable time seems to be elapsing, at least from the system clock perspective. I am using
so when I need to get the time I am setting my time string(startAlgorithm and stopAlgorithm) to:Java Code:public static String now(String dateFormat) { Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat(dateFormat); return sdf.format(cal.getTime()); }
now("H:mm:ss:SSS");
Problem is They are both coming back with the same time, and I am setting the strings at the beginning and the end of the sort(which involves loops and calls to other methods so I know time is elapsing. I don't think I can get any more precision than SSS (millilseconds), can I?
- 04-12-2011, 03:21 PM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 339
- Rep Power
- 5
For measuring elapsed time, try System.nanoTime().
When timing code it's usually also worth running your algorithms multiple times and alternating between them to even out fluctuations due to caching, system performance, garbage collection, etc. It's easy to end up measuring the time it takes to do stuff that's actually quite unrelated to your code.
- 04-12-2011, 03:34 PM #3
Similar Threads
-
24 hour clock to 12 hour clock project.
By bs3ac in forum New To JavaReplies: 4Last Post: 01-08-2013, 10:10 AM -
clock
By ws6driver in forum New To JavaReplies: 1Last Post: 07-31-2009, 04:15 AM -
Desktop Clock
By olamide in forum Threads and SynchronizationReplies: 1Last Post: 03-19-2009, 05:28 PM -
Need help with Java clock
By adz666 in forum New To JavaReplies: 1Last Post: 10-15-2008, 02:18 AM -
Help please in digital clock
By jaidod in forum Java AppletsReplies: 1Last Post: 04-17-2008, 04:05 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks