Skip to content

Commit 6254610

Browse files
committed
Manually unroll calls to avoid loop overhead
1 parent 0921a9e commit 6254610

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

benchmarks/send_bmethod.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,24 @@
55
define_method(:one) { |arg| arg }
66

77
run_benchmark(500) do
8-
2_000_000.times do |i|
8+
500_000.times do |i|
9+
# Manually unrolling to avoid loop overhead
10+
zero
11+
one 123
12+
zero
13+
one 123
14+
zero
15+
one 123
16+
zero
17+
one 123
18+
zero
19+
one 123
20+
zero
21+
one 123
22+
zero
23+
one 123
24+
zero
25+
one 123
926
zero
1027
one 123
1128
end

benchmarks/send_cfunc_block.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,31 @@
33
ARR = []
44

55
run_benchmark(500) do
6-
2_000_000.times do |i|
6+
500_000.times do |i|
77
# each is a 0-arg cfunc
88
ARR.each {}
99
# index is a variadic cfunc
10+
# Manually unrolling to avoid loop overhead
11+
ARR.index {}
12+
ARR.each {}
13+
ARR.index {}
14+
ARR.each {}
15+
ARR.index {}
16+
ARR.each {}
17+
ARR.index {}
18+
ARR.each {}
19+
ARR.index {}
20+
ARR.each {}
21+
ARR.index {}
22+
ARR.each {}
23+
ARR.index {}
24+
ARR.each {}
25+
ARR.index {}
26+
ARR.each {}
27+
ARR.index {}
28+
ARR.each {}
29+
ARR.index {}
30+
ARR.each {}
1031
ARR.index {}
1132
end
1233
end

benchmarks/send_rubyfunc_block.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@ def ruby_func
99
INSTANCE = C.new
1010

1111
run_benchmark(500) do
12-
2_000_000.times do |i|
12+
500_000.times do |i|
13+
# Manually unrolling to avoid loop overhead
14+
INSTANCE.ruby_func {}
15+
INSTANCE.ruby_func {}
16+
INSTANCE.ruby_func {}
17+
INSTANCE.ruby_func {}
18+
INSTANCE.ruby_func {}
19+
INSTANCE.ruby_func {}
20+
INSTANCE.ruby_func {}
21+
INSTANCE.ruby_func {}
1322
INSTANCE.ruby_func {}
1423
end
1524
end

0 commit comments

Comments
 (0)