Page 1 of 1

Help Rubygame: Clock Test

PostPosted: Sun Mar 15, 2009 6:36 pm
by jacius
Hi all, I'm working on improving the Rubygame Clock class, and one of the things I'm investigating is seeing if it's feasible to use ruby's sleep method instead of SDL_Delay. The reason for this is that sleep allows other threads to run, while SDL_Delay (since it's not programmed with ruby in mind) will pause all ruby threads, not just the one that calls it.

But before I do that, I'd like to gather sample data about the granularity of ruby's sleep method on different computers. It would be very helpful if I could get as many people as possible to run this bit of code through IRB and paste the output here, along with your operating system and processor type/speed [edit: and ruby version, please]. :)

Code: Select all
samples = (0..100).collect { t = Time.now; sleep 0.01; Time.now - t }
avg = samples.inject(0){|m,i|m+i} / samples.length
puts "avg: #{avg}; min: #{samples.min}; max: #{samples.max}"

For example, my info would be:

avg: 0.0100623168316832; min: 0.010035; max: 0.010113
Gentoo Linux; AMD Phenom 2.6Ghz Quad (in 32 bit emulation)
ruby 1.8.6 (2008-08-11 patchlevel 287) [i686-linux]

Edit: Also, it would be illuminating if you could run this version, too, with any version of Rubygame:

Code: Select all
require "rubygame"
samples = (0..100).collect {t = Time.now; Rubygame::Clock.wait(10); Time.now - t}
avg = samples.inject(0){|m,i|m+i} / samples.length
puts "rg avg: #{avg}; min: #{samples.min}; max: #{samples.max}"

Re: Help Rubygame: Clock Test

PostPosted: Sun Mar 15, 2009 6:39 pm
by shawn42
Darwin shiny-2.local 9.6.0 Darwin Kernel Version 9.6.0: Mon Nov 24 17:37:00 PST 2008; root:xnu-1228.9.59~1/RELEASE_I386 i386
ruby 1.9.1p0 (2009-01-30 revision 21907) [i386-darwin9.6.0]
avg: 0.0101205049504951; min: 0.010046; max: 0.010638

Re: Help Rubygame: Clock Test

PostPosted: Sun Mar 15, 2009 6:47 pm
by shawn42
ruby 1.8.6 (2007-09-23 patchlevel 110) [i686-darwin8.11.1]
avg: 0.0100987425742574; min: 0.010034; max: 0.010619

Re: Help Rubygame: Clock Test

PostPosted: Sun Mar 15, 2009 6:52 pm
by shawn42
Win XP:
ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]
avg: 0.0106732673267327; min: 0.0; max: 0.016

Re: Help Rubygame: Clock Test

PostPosted: Sun Mar 15, 2009 8:20 pm
by shawn42
ruby 1.8.6 (2007-09-23 patchlevel 110) [i686-darwin8.11.1]
rg avg: 0.0103010594059406; min: 0.010028; max: 0.02898

Re: Help Rubygame: Clock Test

PostPosted: Thu Apr 02, 2009 9:48 pm
by Cyrus
Ubuntu Linux; Intel Core2 duo @2.0GHz
ruby 1.8.6 (2007-09-24 patchlevel 111) [i486-linux]

Using sleep:
avg: 0.0119922376237624; min: 0.008005; max: 0.015985

Using Clock.wait:
avg: 0.0100857821782178; min: 0.010035; max: 0.01063

Re: Help Rubygame: Clock Test

PostPosted: Fri Apr 10, 2009 10:44 pm
by nlr
using sleep:
irb(main):003:0> puts "avg: #{avg}; min: #{samples.min}; max: #{samples.max}"
avg: 0.0119784950495049; min: 0.007477; max: 0.016538

ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]
Ubuntu 8.10; CoreDuo @1.66GHz

Re: Help Rubygame: Clock Test

PostPosted: Thu Jul 02, 2009 8:53 am
by antihcl
First test:
avg: 0.0100726732673267; min: 0.010033; max: 0.010314

Second test:
rg avg: 0.0102148118811881; min: 0.010031; max: 0.021441

Intel(R) Core(TM)2 Duo CPU E7300 @ 2.66GHz
Linux ubuntu 2.6.28-11-generic #42-Ubuntu SMP x86_64 GNU/Linux (Ubuntu 9.04)
ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]


Same system, but in Windows XP running in Virtualbox :-) :
avg: 0.0100792079207921; min: 0.009; max: 0.02

rg avg: 0.0101782178217822; min: 0.009; max: 0.029
(Ruby 186-27)

EDIT: woops, I am totally late to this party.

Re: Help Rubygame: Clock Test

PostPosted: Thu Jul 09, 2009 1:53 pm
by shevegen
CPU: AuthenticAMD, AMD Athlon(tm) Processor LE-1620

My Ruby version:
ruby 1.8.7 (2009-06-08 patchlevel 173) [i686-linux]

Result:

samples = (0..100).collect { t = Time.now; sleep 0.01; Time.now - t }
# => [0.011282, 0.011982, 0.011981, 0.012019, 0.01197, 0.011995, 0.012002, 0.011995, 0.011992, 0.011996, 0.011997, 0.012, 0.011993, 0.012001, 0.011994, 0.011993, 0.011998, 0.011993, 0.01203, 0.012015, 0.011941, 0.011997, 0.011999, 0.011994, 0.011986, 0.01207, 0.011919, 0.012001, 0.011996, 0.011998, 0.011988, 0.011994, 0.011999, 0.011993, 0.011995, 0.012001, 0.011994, 0.011992, 0.011997, 0.011998, 0.011995, 0.012002, 0.012007, 0.01198, 0.011997, 0.012056, 0.011954, 0.012077, 0.011921, 0.012052, 0.011934, 0.011998, 0.012055, 0.011935, 0.011978, 0.011991, 0.011999, 0.011993, 0.011997, 0.011996, 0.011994, 0.011999, 0.011995, 0.011996, 0.011996, 0.011996, 0.011997, 0.011996, 0.011994, 0.012018, 0.012036, 0.011937, 0.011992, 0.011991, 0.011996, 0.011996, 0.011997, 0.011996, 0.011994, 0.011996, 0.011996, 0.012, 0.011993, 0.011993, 0.011997, 0.012003, 0.011996, 0.011991, 0.011993, 0.011997, 0.011996, 0.012001, 0.011997, 0.011992, 0.011996, 0.011994, 0.012, 0.011996, 0.011993, 0.011996, 0.011995]
avg = samples.inject(0){|m,i|m+i} / samples.length # => 0.0119883564356436
puts "avg: #{avg}; min: #{samples.min}; max: #{samples.max}"
avg: 0.0119883564356436; min: 0.011282; max: 0.012077