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 ---+
.



Relevant Pages

  • Re: File Fragmentation
    ... The /aic79xx/ driver can also do this, but the kernel ... * The maximum amount of SCB storage in hardware on a controller. ... For my Maxtor Atlas III drives, that have 512-byte hardware sectors, we have: ... Average seek time: 4.5 milliseconds ...
    (comp.os.linux.misc)
  • Re: vista and VB6
    ... Your previously posted results (685 milliseconds in both cases) confirms ... 2D hardware acceleration but that on your own ... the first time is just 1 millisecond to complete all 100 blits, ... reasons why some video cards might require the software to wait until they ...
    (microsoft.public.vb.general.discussion)
  • Re: simple time server
    ... But I would still need an SNTP server program unlike what's available ... that and it should keep your clock within a hundred milliseconds of the ... server unless you have a machine with a really bad local clock. ... For my computers on the Internet, I have been doing something like ...
    (comp.protocols.time.ntp)
  • Re: neuroimage software - scientific computing and visualization
    ... It will allow seamless communication between your Ruby program ... and an FPGA board acting as hardware accelerator (these boards are available ... Initially it's going to be VHDL, ...
    (comp.lang.ruby)
  • Re: Recent Criticism about Ruby (Scalability, etc.)
    ... Ruby Maniac wrote: ... The 58 servers next year will cost half as much. ... The hardware / software cost analysis turns out different here. ...
    (comp.lang.ruby)