| Author |
Who can explain this?
|
Stephane Clinckart
Ranch Hand
Joined: Oct 21, 2003
Posts: 89
|
|
Who can expalin this ???
Resolution : 15600100ns - 15ms
Resolution Nano System: 810029ns - 0ms
"Resolution" should be lower than "Resolution Nano System" but it is not the case !
Thanks for help.
PS: The original code is from this blog: http://snippets.hoydaa.org/simple-stopwatch-to-calculate-actual-thread-time
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
|
Looking at the values of those four numbers, instead of just looking at the difference between pairs of them, might illuminate the question. Provided you can replicate the phenomenon reliably, that is.
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12269
|
|
Just read the JavaDocs for java.lang.System and you will see that nanoTime has lots of limitations.
Bill
|
Java Resources at www.wbrogden.com
|
 |
Darryl Burke
Bartender
Joined: May 03, 2008
Posts: 4166
|
|
|
Also read UseAMeaningfulSubjectLine
|
luck, db
There are no new questions, but there may be new answers.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32689
|
|
|
Last time I used nanoTime() a lot, it appeared to show the execution time to the nearest ~0.4µs. That will obviously differ from machine to machine.
|
 |
Stephane Clinckart
Ranch Hand
Joined: Oct 21, 2003
Posts: 89
|
|
I'm not sure that I explain well.
What I don't understand is that Sustem.getNano is arround the other way to get the duration.
It looks like both methods are not using the same time referencial internaly.
start1 = getTime()
start2 = getCPUTime()
stop2 = getCPUTime()
stop1 = getTime()
Normally (stop1-start1) should be higger than (stop2-start2)
But it is not the case.
Even if I try in a loop.
Any idea what cause this ???
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12928
|
|
Those timers are not very precise; to start with, their resolution depends on the operating system you're running on and can be as high as 50 ms or so. I also remember reading somewhere that under some circumstances the clock could even seem to be running backwards in time from one moment to the next.
Don't count on these timers to measure very short amounts of time very precisely.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
 |
|
|
subject: Who can explain this?
|
|
|