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

Eric Nicholson enicholson at gmail.com
Wed Feb 6 15:04:20 EST 2008


Whoops, had the stopwatch setup wrong in that last message

require 'mscorlib'
require 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll'

a = (1..1000).to_a
1000.times {
    s = System::Diagnostics::Stopwatch.new()
    s.start
    a.find {|x| x == 1000}
    s.stop
    puts "find took: #{s.elapsed.ToString}"
}

and the output is:

find took: 00:00:00.0732210
find took: 00:00:00.0048562
find took: 00:00:00.0022469
find took: 00:00:00.0021351
... snip ...

find took: 00:00:00.0196016
find took: 00:00:00.0201994
find took: 00:00:00.0218765
... snip ...
find took: 00:00:00.0371834
find took: 00:00:00.0367817
find took: 00:00:00.0361911


On Feb 6, 2008 2:38 PM, Eric Nicholson <enicholson at gmail.com> wrote:

> I noticed some strange issues in an application I'm working on where it
> works speedy at first, and then gets progressively slower and slower.  After
> a little bit of investigation, it seems that Enumerable#find is the
> culprit.  The more times you run a find statement the slower it gets.  Does
> anybody have any ideas why this is?
>
> Here's a sample that demonstrates the issue:
>
> 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}"
> }
>
> which outputs:
>
> find took: 00:00:00.0743446
> ...snip...
> find took: 00:00:00.2290894
> ...snip...
> find took: 00:00:00.4942105
>
> I understand you guys aren't optimizing yet, but I thought you might be
> interested to see growth where there shouldn't be any.  Also, if you have
> any ideas off the top of your head, I wouldn't mind looking into it a
> little.
>
> -Eric
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/ironruby-core/attachments/20080206/270140e9/attachment-0001.html 


More information about the Ironruby-core mailing list