Feature #13436
Improve performance of Array#<=> with Fixnum/Float/String elements
Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
Description
Array#<=> will be ~7.5 times faster with Fixnum elements.
Before¶
user system total real Fixnum 2.020000 0.010000 2.030000 ( 2.022351) Float 2.180000 0.000000 2.180000 ( 2.185891) String 2.290000 0.000000 2.290000 ( 2.289221)
After¶
user system total real Fixnum 0.260000 0.000000 0.260000 ( 0.266339) Float 0.760000 0.000000 0.760000 ( 0.754436) String 0.520000 0.000000 0.520000 ( 0.529152)
Test code¶
require 'benchmark' Benchmark.bmbm do |x| x.report "Fixnum" do ary1 = Array.new(1000) { rand(1000) } ary2 = ary1.dup 50000.times do ary1 <=> ary2 end end x.report "Float" do ary1 = Array.new(1000) { rand } ary2 = ary1.dup 50000.times do ary1 <=> ary2 end end x.report "String" do ary1 = Array.new(1000) { rand(1000).to_s } ary2 = ary1.dup 50000.times do ary1 <=> ary2 end end end
Patch¶
Updated by jeremyevans0 (Jeremy Evans) over 1 year ago
- Backport deleted (
2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN) - Tracker changed from Bug to Feature