Skip to content

Commit 0921a9e

Browse files
authored
Add microbenchmarks for more kinds of sends (#421)
1 parent b4c36d2 commit 0921a9e

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

benchmarks.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@ cfunc_itself:
112112
desc: cfunc_itself just calls the 'itself' method many, many times.
113113
category: micro
114114
single_file: true
115+
send_cfunc_block:
116+
desc: send_cfunc_block just calls a known C function with a block many, many times.
117+
category: micro
118+
single_file: true
119+
send_rubyfunc_block:
120+
desc: send_rubyfunc_block just calls a known Ruby function with a block many, many times.
121+
category: micro
122+
single_file: true
123+
send_bmethod:
124+
desc: send_bmethod just calls known Ruby bmethods many, many times.
125+
category: micro
126+
single_file: true
115127
fib:
116128
desc: Fib is a simple exponential-time recursive Fibonacci number generator.
117129
category: micro

benchmarks/send_bmethod.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require_relative '../harness/loader'
2+
3+
# Call with and without args
4+
define_method(:zero) { :b }
5+
define_method(:one) { |arg| arg }
6+
7+
run_benchmark(500) do
8+
2_000_000.times do |i|
9+
zero
10+
one 123
11+
end
12+
end

benchmarks/send_cfunc_block.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require_relative '../harness/loader'
2+
3+
ARR = []
4+
5+
run_benchmark(500) do
6+
2_000_000.times do |i|
7+
# each is a 0-arg cfunc
8+
ARR.each {}
9+
# index is a variadic cfunc
10+
ARR.index {}
11+
end
12+
end

benchmarks/send_rubyfunc_block.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require_relative '../harness/loader'
2+
3+
class C
4+
def ruby_func
5+
# Don't even yield
6+
end
7+
end
8+
9+
INSTANCE = C.new
10+
11+
run_benchmark(500) do
12+
2_000_000.times do |i|
13+
INSTANCE.ruby_func {}
14+
end
15+
end

0 commit comments

Comments
 (0)