From: Kero Date: 2005-11-11T18:07:13+09:00 Subject: Re: Accurate Timing in ruby > Believe it or not, I'm attempting to make an action-driven game with ruby > Is there a way to get the time in milliseconds since the program start > ed, or something similar? I've tried using Time.now.to_f, but all too of > ten that value will be the same in two consecutive update calls, causing > jumps in motion and "infinite" fps readings. I typically & rather consistently get: irb(main):003:0> Time.now - Time.now => -5.0e-06 meaning Ruby evaluates from right to left and my clock is running nice and smooth (on microsecond level) I fear what you see is not Ruby's fault, but your hardware/OS clock. 1) your hardware is so fast that the consecutive calls have no significant distinguishing bits left (I have 2 or 3 bits left on 700 MHz; you may need nanoseconds instead of microseconds) 2) your OS is not updating its system clock often enough Even though windows has nasty habits when updating time to a central server, I do not think it suffers from 2) You don't round to milliseconds before you compute the fps, do you? Then you would get zero whenever you're near 1000 fps (which --depending on the action-- is quite possible on today's hardware; even my puny CPU and reasonable graphics card have 1200fps on the glxgears test) Hth, Kero. +--- Kero ---------------------------------- kero@chello@nl ---+ | The last good thing written in C++ was the Pachelbel Canon | | Jerry Olson | +--- M38c ------------ http://members.chello.nl/k.vangelder ---+