Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ attr_accessor:
category: micro
single_file: true
ractor: true
block_methods:
desc: calls a handful of builtin Ruby methods that take blocks.
category: micro
single_file: true
cfunc_itself:
desc: cfunc_itself just calls the 'itself' method many, many times.
category: micro
Expand Down
79 changes: 79 additions & 0 deletions benchmarks/block_methods.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
require_relative '../harness/loader'

def array_each(array)
array.each do |x|
x * 2
end
array.each do |x|
x * 4
end
end

def array_map(array)
array.map do |x|
x * 2
end
array.map do |x|
x * 4
end
end

def array_select(array)
array.select do |x|
x.even?
end
array.select do |x|
x.odd?
end
end

def integer_times(integer)
integer.times do |i|
i * 2
end
integer.times do |i|
i * 4
end
end

def kernel_tap(x)
i = 0
while i < x
x.tap do |y|
y * 2
end
x.tap do |y|
y * 4
end
i += 1
end
end

def kernel_then(x)
i = 0
while i < x
x.then do |y|
y * 2
end
x.then do |y|
y * 4
end
i += 1
end
end

K = 100_000
ARRAY = (1..K).to_a

run_benchmark(1000) do
i = 0
while i < 10
array_each(ARRAY)
array_map(ARRAY)
array_select(ARRAY)
integer_times(K)
kernel_tap(K)
kernel_then(K)
i += 1
end
end
Loading