From 082f416489d974645e80938071474a2aa449987a Mon Sep 17 00:00:00 2001 From: Max Bernstein Date: Fri, 17 Oct 2025 13:14:27 -0400 Subject: [PATCH 1/4] Add microbenchmarks for sending to a methods with a block --- benchmarks.yml | 8 ++++++++ benchmarks/send_cfunc_block.rb | 9 +++++++++ benchmarks/send_rubyfunc_block.rb | 15 +++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 benchmarks/send_cfunc_block.rb create mode 100644 benchmarks/send_rubyfunc_block.rb diff --git a/benchmarks.yml b/benchmarks.yml index b0406a93..d03a8ed8 100644 --- a/benchmarks.yml +++ b/benchmarks.yml @@ -112,6 +112,14 @@ cfunc_itself: desc: cfunc_itself just calls the 'itself' method many, many times. category: micro single_file: true +send_cfunc_block: + desc: send_cfunc_block just calls a known C function with a block many, many times. + category: micro + single_file: true +send_rubyfunc_block: + desc: send_rubyfunc_block just calls a known Ruby function with a block many, many times. + category: micro + single_file: true fib: desc: Fib is a simple exponential-time recursive Fibonacci number generator. category: micro diff --git a/benchmarks/send_cfunc_block.rb b/benchmarks/send_cfunc_block.rb new file mode 100644 index 00000000..141a43b9 --- /dev/null +++ b/benchmarks/send_cfunc_block.rb @@ -0,0 +1,9 @@ +require_relative '../harness/loader' + +ARR = [] + +run_benchmark(500) do + 2_000_000.times do |i| + ARR.each {} + end +end diff --git a/benchmarks/send_rubyfunc_block.rb b/benchmarks/send_rubyfunc_block.rb new file mode 100644 index 00000000..1edabf26 --- /dev/null +++ b/benchmarks/send_rubyfunc_block.rb @@ -0,0 +1,15 @@ +require_relative '../harness/loader' + +class C + def ruby_func + # Don't even yield + end +end + +INSTANCE = C.new + +run_benchmark(500) do + 2_000_000.times do |i| + INSTANCE.ruby_func {} + end +end From 9e608d1584ea2d11df1c9f949de76a46dbf935e2 Mon Sep 17 00:00:00 2001 From: Max Bernstein Date: Fri, 17 Oct 2025 13:19:56 -0400 Subject: [PATCH 2/4] . --- benchmarks/send_cfunc_block.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/benchmarks/send_cfunc_block.rb b/benchmarks/send_cfunc_block.rb index 141a43b9..f8551e6d 100644 --- a/benchmarks/send_cfunc_block.rb +++ b/benchmarks/send_cfunc_block.rb @@ -4,6 +4,9 @@ run_benchmark(500) do 2_000_000.times do |i| + # each is a 0-arg cfunc ARR.each {} + # index is a variadic cfunc + ARR.index {} end end From b0bb57e8bea30b3961c35a492132be4a608258c1 Mon Sep 17 00:00:00 2001 From: Max Bernstein Date: Mon, 20 Oct 2025 09:28:53 -0400 Subject: [PATCH 3/4] Add bmethod benchmark --- benchmarks.yml | 4 ++++ benchmarks/send_bmethod.rb | 11 +++++++++++ 2 files changed, 15 insertions(+) create mode 100644 benchmarks/send_bmethod.rb diff --git a/benchmarks.yml b/benchmarks.yml index d03a8ed8..d0c4f586 100644 --- a/benchmarks.yml +++ b/benchmarks.yml @@ -120,6 +120,10 @@ send_rubyfunc_block: desc: send_rubyfunc_block just calls a known Ruby function with a block many, many times. category: micro single_file: true +send_bmethod: + desc: send_bmethod just calls a known Ruby bmethod many, many times. + category: micro + single_file: true fib: desc: Fib is a simple exponential-time recursive Fibonacci number generator. category: micro diff --git a/benchmarks/send_bmethod.rb b/benchmarks/send_bmethod.rb new file mode 100644 index 00000000..9f39ca8d --- /dev/null +++ b/benchmarks/send_bmethod.rb @@ -0,0 +1,11 @@ +require_relative '../harness/loader' + +define_method(:zero) { :b } +define_method(:one) { |arg| arg } + +run_benchmark(500) do + 2_000_000.times do |i| + zero + one 123 + end +end From 884bec81459655d74fe053bf4d3778bb64350075 Mon Sep 17 00:00:00 2001 From: Max Bernstein Date: Mon, 20 Oct 2025 10:03:07 -0400 Subject: [PATCH 4/4] . --- benchmarks.yml | 2 +- benchmarks/send_bmethod.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/benchmarks.yml b/benchmarks.yml index d0c4f586..906713a3 100644 --- a/benchmarks.yml +++ b/benchmarks.yml @@ -121,7 +121,7 @@ send_rubyfunc_block: category: micro single_file: true send_bmethod: - desc: send_bmethod just calls a known Ruby bmethod many, many times. + desc: send_bmethod just calls known Ruby bmethods many, many times. category: micro single_file: true fib: diff --git a/benchmarks/send_bmethod.rb b/benchmarks/send_bmethod.rb index 9f39ca8d..6b3a28b7 100644 --- a/benchmarks/send_bmethod.rb +++ b/benchmarks/send_bmethod.rb @@ -1,5 +1,6 @@ require_relative '../harness/loader' +# Call with and without args define_method(:zero) { :b } define_method(:one) { |arg| arg }