|
I have a question about Java nanoTime. I'm trying to use it to measure the running time of some code and most of the time it returns a value around 130,000, but sometimes it returns values around 3,750,000 or -3,750,000. I'm running a dual core processor on windows and my only theory is that the dual core is messing up the nanoTime call somehow. Any ideas on what is happening/how to fix it?
|
# ¿ Mar 5, 2009 05:59 |
|
|
# ¿ May 20, 2024 07:17 |
|
dancavallaro posted:nanoTime makes no guarantees about the *accuracy* of the time, only the *precision*. Meaning, you can't use System.nanoTime() to actually get an accurate measure of the current time, but the difference between two calls to nanoTime is the most precise elapsed time measurement possible in Java. Yeah but telling me my program finishes 3ms before it starts seems a little off Edit: Yeah, i'm subtracting the time before from the time after, it just sometimes gives negative results Moon Whaler fucked around with this message at 06:17 on Mar 5, 2009 |
# ¿ Mar 5, 2009 06:15 |
|
csammis posted:Is it possible that the data type you're using to store the nanoTime result (or the subtraction result) is overflowing and wrapping? I don't think so, I'm using a long. I'm pretty sure what' happening is sometimes it tries to compare times given by two different processors and gets a garbage result. I guess I'll just have to run it on another machine.
|
# ¿ Mar 5, 2009 19:39 |