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

Michael Letterle michael.letterle at gmail.com
Wed Feb 6 19:18:46 EST 2008


I don't know if i'd call it a "red herring" as the performance with
find dropped considerably faster, it's probably a combination.

On Feb 6, 2008 6:56 PM, Eric Nicholson <enicholson at gmail.com> wrote:
> 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
> >
>
>
> _______________________________________________
> 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