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

Michael Letterle michael.letterle at gmail.com
Wed Feb 6 16:22:48 EST 2008


I have some ideas on what some of the issues may be, primarily related
to how the Enumerable class creates a new Proc object every time
through the loop.  Anyway, doing the following seems to help to some
extent:

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

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

find took: 00:00:00.0012998
find took: 00:00:00.0012719
find took: 00:00:00.0012915

[snip]

find took: 00:00:00.0049048
find took: 00:00:00.0052548
find took: 00:00:00.0051403

[snip]

find took: 00:00:00.0127650
find took: 00:00:00.0141006
find took: 00:00:00.0106432

You can see the times still going up (rules are being created based on
Proc.Id?)  but not nearly the same pace.

On Feb 6, 2008 3:31 PM, M. David Peterson <m.david at xmlhacker.com> wrote:
> On Wed, 06 Feb 2008 13:23:10 -0700, Michael Letterle
> <michael.letterle at gmail.com> wrote:
>
> > He's right about the issue however:
> > ...
> > find took: 00:00:00.0377458
> > find took: 00:00:00.0453373
> > find took: 00:00:00.0369415
>
> Whoops.  My bad.  I was testing via Ruby.NET which, coincidentally,
> doesn't showcase this type of behavior,
>
> find took: 00:00:00.0216940
> find took: 00:00:00.0012342
> find took: 00:00:00.0012423
> ...
> find took: 00:00:00.0013994
> find took: 00:00:00.0013016
> find took: 00:00:00.0017697
> ...
> find took: 00:00:00.0012989
> find took: 00:00:00.0014228
> find took: 00:00:00.0013389
> ...
>
> I guess maybe Ruby.NET still has its place in this world afterall. ;-) :D
>
> ---
>
> (the modified code in case anyone wants to run the comparison on their own
> machine)
>
> 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}"
>      s.Reset
> }
>
> --
>
> /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
> _______________________________________________
> Ironruby-core mailing list
> Ironruby-core at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ironruby-core
>



-- 
Michael Letterle
[Polymath Programmer]
http://michaeldotnet.blogspot.com


More information about the Ironruby-core mailing list