Ruby 2.0 slower than 1.9.3?

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.

On Mar 3, 2013, at 14:04, Bug F. [email protected] 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. 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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs