# Surprising Result

**URL:** <https://www.ruby-forum.com/t/surprising-result/131517>\
**Category:** IronRuby\
**Created:** [March 10, 2008, 10:22pm UTC](https://www.ruby-forum.com/t/surprising-result/131517 "2008-03-10T22:22:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [March 10, 2008, 10:22pm UTC](https://www.ruby-forum.com/t/surprising-result/131517/1 "2008-03-10T22:22:19Z")

</div>

I’d just gotten done implementing DEFLATE in pure ruby, and figuring  
there’d be a performance hit I was interested to see what it would be.  
On IronRuby (compiled in Release) it takes a full 16 seconds to  
decompress a ~1KB file… in CRuby it’s less then a second. An ~800KB  
file takes 42 seconds in CRuby, while IronRuby takes a whopping…  
well I don’t know, I killed it after it was running for about a half  
hour and using upwards of 100MB of memory!

Now this is just a straight port of “puff.c” from the zlib library, so  
it’s certainly not optimized for speed in any way, but the difference  
in runtimes really struck me.

I suppose at the very least we have a good stress test for rbx 😉  
Just thought I’d share.

–  
Michael L.  
[Polymath Prokrammer]  
[http://blog.prokrams.com](http://blog.prokrams.com)

---

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [March 10, 2008, 10:36pm UTC](https://www.ruby-forum.com/t/surprising-result/131517/2 "2008-03-10T22:36:37Z")

</div>

Michael L.:

> in runtimes really struck me.
> 
> I suppose at the very least we have a good stress test for rbx 😉 Just  
> thought I’d share.

Cool 🙂 Can you send along the source code for your implementation so we  
can investigate?

Thanks  
-John

---

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [March 10, 2008, 11:08pm UTC](https://www.ruby-forum.com/t/surprising-result/131517/3 "2008-03-10T23:08:31Z")

</div>

I’ll be posting it up (probably on RubyForge) once I get cleaned up a  
bit (acknowledgments, rdoc stuff), if you want the raw stuff I can  
email it straight to you.

On Mon, Mar 10, 2008 at 5:33 PM, John L. (DLR) [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > hour and using upwards of 100MB of memory!  
> > Thanks  
> > -John
> 
> * * *
> 
> Ironruby-core mailing list  
> removed\_email\_address@domain.invalid  
> [http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)

–  
Michael L.  
[Polymath Prokrammer]  
[http://blog.prokrams.com](http://blog.prokrams.com)

---

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [March 10, 2008, 11:45pm UTC](https://www.ruby-forum.com/t/surprising-result/131517/4 "2008-03-10T23:45:43Z")

</div>

Don’t know what I’m going to do with a nickel…

Actually since it’s basically a port of a c program I’m only really  
using blocks in two places, input and output, plus on other little  
place… I can try but I’d be surprised… unless for loops in a range  
count…

On Mon, Mar 10, 2008 at 6:37 PM, Eric N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > bit (acknowledgments, rdoc stuff), if you want the raw stuff I can
> > 
> > > > Now this is just a straight port of “puff.c” from the zlib library,
> > 
> > removed\_email\_address@domain.invalid  
> > [http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)
> 
> * * *
> 
> Ironruby-core mailing list  
> removed\_email\_address@domain.invalid  
> [http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)

–  
Michael L.  
[Polymath Prokrammer]  
[http://blog.prokrams.com](http://blog.prokrams.com)

---

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [March 11, 2008, 3:04pm UTC](https://www.ruby-forum.com/t/surprising-result/131517/5 "2008-03-11T15:04:54Z")

</div>

Alright, I’ll bet you a beer next time you’re in Raleigh, NC. 🙂

For… in loops seem to use blocks. Anyway, in a quick test they seem  
to be  
about 200 - 1000 times slower than an equivalent while loop. A quick  
test  
that runs through 1000 iterations 2000 times takes 0.3s with a while  
loop,  
and 9.0s with a for loop on my system.

Try a while loop…  
-Eric

On Mon, Mar 10, 2008 at 6:44 PM, Michael L. \<

---

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [March 10, 2008, 11:39pm UTC](https://www.ruby-forum.com/t/surprising-result/131517/6 "2008-03-10T23:39:15Z")

</div>

I bet you a nickel that if you replace a few key block loops (i.e. each,  
times, etc) with a vanilla while loop that you’ll see a 10x speedup…  
I’ve  
seen some really huge performance hits on IR using blocks.

-Eric  
On Mon, Mar 10, 2008 at 6:06 PM, Michael L. \<

---

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [March 11, 2008, 4:39pm UTC](https://www.ruby-forum.com/t/surprising-result/131517/7 "2008-03-11T16:39:20Z")

</div>

So I did some testing on this, I wrapped all loops in an outer while  
loop and ran them though both rbx and cruby:  
i.e.  
t = 0  
while t \< 2000  
for i in (1…1000)  
end  
t+=1  
end

cruby:  
while: 0:01.22  
for: 0:00.46  
times: 0:00.75

rbx:  
while: 0:01.83  
for: 0:24.53  
times: 0:24.84

Of course this is just a couple of runs, it would be more accurate to  
do a whole suite and average them out, but I ran them a few times and  
the times were relatively consistent.

Work to be done…

On Tue, Mar 11, 2008 at 9:57 AM, Eric N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > > > On Mon, Mar 10, 2008 at 5:33 PM, John L. (DLR) [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
> > > > 
> > > > > > On IronRuby (compiled in Release) it takes a full 16 seconds to  
> > > > > > so  
> > > > > > we can investigate?
> > > > 
> > > > Ironruby-core mailing list
> > 
> > [http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)
> 
> * * *
> 
> Ironruby-core mailing list  
> removed\_email\_address@domain.invalid  
> [http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)

–  
Michael L.  
[Polymath Prokrammer]  
[http://blog.prokrams.com](http://blog.prokrams.com)
