Actions
Feature #13342
openImprove yielding block performance
Status:
Open
Assignee:
-
Target version:
-
Description
The yielding block will be faster around 9%.
This patch ensures that expand to inline codes in where invoke yielding block.
Environment¶
- macOS 10.12.3
- clang 8.0.0 in Xcode 8.2
Before¶
user system total real
Integer#times 0.930000 0.000000 0.930000 ( 0.932125)
Array#each 0.950000 0.000000 0.950000 ( 0.957962)
Array#map 1.220000 0.030000 1.250000 ( 1.249174)
After¶
user system total real
Integer#times 0.850000 0.000000 0.850000 ( 0.853202)
Array#each 0.860000 0.010000 0.870000 ( 0.865507)
Array#map 1.120000 0.020000 1.140000 ( 1.149939)
Test code¶
require 'benchmark'
Benchmark.bmbm do |x|
ary = (1..10000).to_a
x.report "Integer#times" do
20000000.times do
end
end
x.report "Array#each" do
2000.times do
ary.each { |x| }
end
end
x.report "Array#map" do
2000.times do
ary.map { |x| }
end
end
end
Patch¶
The patch is in https://github.com/ruby/ruby/pull/1535
Actions
Like0
Like0Like0