Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Who can explain this?

 
Stephane Clinckart
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just read the JavaDocs for java.lang.System and you will see that nanoTime has lots of limitations.

Bill
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also read UseAMeaningfulSubjectLine
 
Campbell Ritchie
Sheriff
Pie
Posts: 50258
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 15492
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic