# Ruby 2.0 slower than 1.9.3?

**URL:** <https://www.ruby-forum.com/t/ruby-2-0-slower-than-1-9-3/227085>\
**Category:** Ruby\
**Created:** [March 3, 2013, 11:04pm UTC](https://www.ruby-forum.com/t/ruby-2-0-slower-than-1-9-3/227085 "2013-03-03T23:04:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![x17y19](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/a88e57/32.png) [@x17y19](https://www.ruby-forum.com/u/x17y19)\
**Post date:** [March 3, 2013, 11:04pm UTC](https://www.ruby-forum.com/t/ruby-2-0-slower-than-1-9-3/227085/1 "2013-03-03T23:04:14Z")

</div>

I’m running a simple CPU intensive benchmark:

puts (0…11).to\_a.permutation.inject(0) { |m, \_| m += 1 }

This takes around 158s with 1.9.3 and 200s with 2.0. Any thoughts on how  
I can get performance back ?

Thanks.

---

<div class="post-metadata">

**Author:** ![x17y19](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/a88e57/32.png) [@x17y19](https://www.ruby-forum.com/u/x17y19)\
**Post date:** [March 4, 2013, 6:00am UTC](https://www.ruby-forum.com/t/ruby-2-0-slower-than-1-9-3/227085/2 "2013-03-04T06:00:24Z")

</div>

On Mar 3, 2013, at 14:04, Bug F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m running a simple CPU intensive benchmark:
> 
> puts (0..11).to\_a.permutation.inject(0) { |m, \_| m += 1 }
> 
> This takes around 158s with 1.9.3 and 200s with 2.0. Any thoughts on how  
> I can get performance back ?

I suggest you file a bug on [http://bugs.ruby-lang.org](http://bugs.ruby-lang.org). I also see the  
performance drop, about 8%.

I profiled a smaller benchmark:

$ ruby19 -v -rprofile -e ‘(0..7).to\_a.permutation.inject(0) { |m, \_| m  
+= 1 }’  
ruby 1.9.3p374 (2013-01-15 revision 38858) [x86\_64-darwin12.2.1]  
% cumulative self self total  
time seconds seconds calls ms/call ms/call name  
75.00 0.27 0.27 2 135.00 180.00 Array#permutation  
25.00 0.36 0.09 40320 0.00 0.00 Fixnum#+  
0.00 0.36 0.00 1 0.00 0.00 Range#each  
0.00 0.36 0.00 1 0.00 0.00 Enumerable.to\_a  
0.00 0.36 0.00 1 0.00 360.00 Enumerator#each  
0.00 0.36 0.00 1 0.00 360.00 Enumerable.inject  
0.00 0.36 0.00 1 0.00 360.00 #toplevel

I’m unsure what this “nil#” method ruby 2 records is, or if it is only  
an artifact of TracePoint. It’s also worth a bug report.

$ ruby -v -rprofile -e ‘(0..7).to\_a.permutation.inject(0) { |m, \_| m +=  
1 }’  
ruby 2.0.0p0 (2013-02-24 revision 39473) [x86\_64-darwin12.2.1]  
% cumulative self self total  
time seconds seconds calls ms/call ms/call name  
52.31 0.34 0.34 40320 0.01 0.01 nil#  
35.38 0.57 0.23 2 115.00 325.00 Array#permutation  
12.31 0.65 0.08 40320 0.00 0.00 Fixnum#+  
0.00 0.65 0.00 1 0.00 0.00 TracePoint#enable  
0.00 0.65 0.00 1 0.00 0.00 Enumerable#to\_a  
0.00 0.65 0.00 1 0.00 0.00 Range#each  
0.00 0.65 0.00 1 0.00 650.00 Enumerator#each  
0.00 0.65 0.00 1 0.00 650.00 Enumerable#inject  
0.00 0.65 0.00 1 0.00 0.00 TracePoint#disable  
0.00 0.65 0.00 1 0.00 650.00 #toplevel
