Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (546)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Javadoc description of System.nanoTime()  (Read 3326 times)
0 Members and 1 Guest are viewing this topic.
Offline 2playgames

Junior Member





« Posted 2007-07-04 13:05:22 »

Quote
Returns the current value of the most precise available system timer, in nanoseconds.

This method can only be used to measure elapsed time and is not related to any other notion of system or wall-clock time. The value returned represents nanoseconds since some fixed but arbitrary time (perhaps in the future, so values may be negative). This method provides nanosecond precision, but not necessarily nanosecond accuracy. No guarantees are made about how frequently values change. Differences in successive calls that span greater than approximately 292 years (2^63 nanoseconds) will not accurately compute elapsed time due to numerical overflow.

look at the last bit. i mean, seriously, who is going to run a java app for 300 years  Roll Eyes a computer doesn't even live that long, let alone stay up

Offline fletchergames

Senior Member





« Reply #1 - Posted 2007-07-04 15:09:09 »

Even so, System.nanoTime() doesn't work well on computers with dual core processors because it sometimes gets the time from the wrong core.  That's why System.nanoTime() is evil (as discussed in some other thread).
Offline 2playgames

Junior Member





« Reply #2 - Posted 2007-07-04 15:15:30 »

but what if you use it in 1 thread? i suppose it will always get the time from the same core then?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ryanm

Senior Member


Projects: 1
Exp: 15 years


Used to be bleb


« Reply #3 - Posted 2007-07-04 15:37:48 »

I wouldn't be surprised if threads can get shunted from core to core without warning.
Offline princec

JGO Kernel


Medals: 361
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #4 - Posted 2007-07-04 15:44:29 »

Threads bounce from one core to another without warning and there's no API call to set their affinity in Java yet. Maybe we'll add one to LWJGL.

Cas Smiley

Offline brackeen

Junior Member





« Reply #5 - Posted 2007-07-04 18:50:48 »

Here's a pretty good blog about the issue: http://blogs.sun.com/dholmes/entry/inside_the_hotspot_vm_clocks
And here's a Microsoft KB article: http://support.microsoft.com/kb/895980
It seems AMD has particular issues, however, it looks like it might have been fixed in Windows XP Service Pack 2:

Quote
For example Windows XP Service Pack 2 changed things to use the power management timer (PMTimer) rather than the processor timestamp-counter (TSC) due to problems with the TSC not being synchronized on different processors in SMP systems, and due the fact its frequency can vary (and hence it's relationship to elapsed time) based on power-management settings.

Any Windows AMD users want to chime in with their experience?
Offline broumbroum

Junior Member





« Reply #6 - Posted 2007-07-04 22:57:42 »

What about using NanoTimings if your data is loaded in RAM? Wouldn't that be the best solution regarding the RAM running @ averaging 9ns, would it? And for disk storage, this wouldn't be the case, averaging the HDD r/w access to 10ms....

::::... :..... :::::: ;;;:::™ b23:production 2006 GNU/GPL @ http://b23prodtm.webhop.info
on sf.net: /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
Offline EgonOlsen
« Reply #7 - Posted 2007-07-05 07:27:59 »

Any Windows AMD users want to chime in with their experience?
I never had a single problem using System.nanoTime() on dual core cpus. Neither AMD based nor Intel based.

Offline princec

JGO Kernel


Medals: 361
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #8 - Posted 2007-07-05 08:54:36 »

I've experienced various problems but we switched to timeGetTime in LWJGL-Win32 which is 1ms accurate and doesn't fluctuate.

Cas Smiley

Offline EgonOlsen
« Reply #9 - Posted 2007-07-05 08:59:28 »

I've experienced various problems but we switched to timeGetTime in LWJGL-Win32 which is 1ms accurate and doesn't fluctuate.
...but runs twice as fast on some machines and in some applications due to a VM bug?  Wink

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline kevglass

JGO Kernel


Medals: 152
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #10 - Posted 2007-07-05 10:54:17 »

I've seen jumps and running double time on AMD dual, never on an intel.

Annoying timing artefacts in Java arn't limited to checking the time tho, sleep() gets hit just the same.

Kev

Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #11 - Posted 2007-07-05 14:21:38 »

I think the problem with the LWJGL timer EgonOlsen is referring to (I've hit the same problem too) doesn't have anything to do with the timing method itself but is totally due to a VM bug (which I haven't been able to isolate though). I've never seen the same problem with System.currentTimeMillis.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (23 views)
2014-08-19 09:29:53

Tekkerue (22 views)
2014-08-16 06:45:27

Tekkerue (21 views)
2014-08-16 06:22:17

Tekkerue (12 views)
2014-08-16 06:20:21

Tekkerue (19 views)
2014-08-16 06:12:11

Rayexar (57 views)
2014-08-11 02:49:23

BurntPizza (37 views)
2014-08-09 21:09:32

BurntPizza (29 views)
2014-08-08 02:01:56

Norakomi (36 views)
2014-08-06 19:49:38

BurntPizza (66 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!