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

Eric Nicholson enicholson at gmail.com
Wed Feb 6 18:56:35 EST 2008


So "Enumerable#find" is definitely a red herring.  I'm guessing it has
something to do with block creation.  Here's a better example without the
find:

10000.times { | iter |
    s.reset
    s.start
    x = 0
    1000.times { x += 1}
    s.stop
    puts "iteration #{iter} took: #{s.elapsed.ToString}" if iter % 100 == 0
}
Output:

iteration 0 took: 00:00:00.0471160
iteration 100 took: 00:00:00.0024187
iteration 200 took: 00:00:00.0037267
iteration 300 took: 00:00:00.0039901
iteration 400 took: 00:00:00.0054012
iteration 500 took: 00:00:00.0063639
iteration 600 took: 00:00:00.0070567
iteration 700 took: 00:00:00.0103230
iteration 800 took: 00:00:00.0093428
iteration 900 took: 00:00:00.0095257
[snip]
iteration 9700 took: 00:00:00.0892543
iteration 9800 took: 00:00:00.0899337
iteration 9900 took: 00:00:00.0963234

It's very consistent linear growth.   Several iterations took much longer
presumably due to garbage collection.

Compare that to this version without the inner block:

1000.times do |iter|
    s.reset
    s.start
    x = 0
    x+= 1 while x < 1000
    s.stop
    puts "iteration #{iter} took: #{s.elapsed.ToString}" if iter % 100 == 0
    iter += 1
end

Output:

iteration 0 took: 00:00:00.1119421
iteration 100 took: 00:00:00.0001190
iteration 200 took: 00:00:00.0001430
iteration 300 took: 00:00:00.0001326
iteration 400 took: 00:00:00.0001212
iteration 500 took: 00:00:00.0001173
iteration 600 took: 00:00:00.0001190
iteration 700 took: 00:00:00.0001178
iteration 800 took: 00:00:00.0001176
iteration 900 took: 00:00:00.0001178
[snip]
iteration 9900 took: 00:00:00.0001142

So maybe block creation/parsing/execution is a little slower each time?

On Feb 6, 2008 6:06 PM, Michael Letterle <michael.letterle at gmail.com> wrote:

> Bug has been submitted.  I'll probably poke it with a stick some while
> I'm at it.
>
> On Feb 6, 2008 5:58 PM, John Lam (DLR) <jflam at microsoft.com> wrote:
> > Michael Letterle:
> >
> >
> > > 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
> >
> > This is a strange; nothing obvious jumps out right now. We'll have to
> look at this down the road when we do our perf push. Clearly this is a bug.
> Can someone open up a bug for this?
> >
> > Thanks,
> > -John
> >
> >
> > _______________________________________________
> > Ironruby-core mailing list
> > Ironruby-core at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/ironruby-core
> >
>
>
>
> --
> Michael Letterle
> [Polymath Programmer]
> http://michaeldotnet.blogspot.com
> _______________________________________________
> Ironruby-core mailing list
> Ironruby-core at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ironruby-core
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/ironruby-core/attachments/20080206/c3f1117e/attachment-0001.html 


More information about the Ironruby-core mailing list