[Ironruby-core] Weird performance problem with "find"

M. David Peterson m.david at xmlhacker.com
Wed Feb 6 15:13:36 EST 2008


On Wed, 06 Feb 2008 12:38:46 -0700, Eric Nicholson <enicholson at gmail.com>  
wrote:

> require 'mscorlib'
> require 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll'
>
> a = (1..1000).to_a
> s = System::Diagnostics::Stopwatch.new()
>
> 100.times {
>     s.start
>     a.find {|x| x == 1000}
>     s.stop
>     puts "find took: #{s.elapsed.ToString}"
> }


You're reusing the same Stopwatch instance, so you have to add a call to  
the Reset method at the end of each iteration.  In doing so you should  
find your timings are as they should be.


-- 
/M:D

M. David Peterson
Co-Founder & Chief Architect, 3rd&Urban, LLC
Email: m.david at 3rdandUrban.com | m.david at amp.fm
Mobile: (206) 418-9027
http://3rdandUrban.com | http://amp.fm |  
http://www.oreillynet.com/pub/au/2354


More information about the Ironruby-core mailing list