Skip to content
Merged
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 @@ -147,3 +147,7 @@ ruby-xor:
desc: pure-Ruby string XOR microbenchmark, analogous to xorcist C extension.
category: micro
single_file: true
loops-times:
desc: nested loop Integer#times and array access microbenchmark
category: micro
single_file: true
21 changes: 21 additions & 0 deletions benchmarks/loops-times.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require_relative '../harness/loader'

# Fix these values for determinism
u = 5
r = 7

run_benchmark(10) do
a = Array.new(10000, 0)

4_000.times do |i|
4_000.times do |j|
a[i] += j % u
Copy link
Member

@eregon eregon Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This modulo in the inner loop likely dominates the benchmark, I'd suggest to use & 0b111 or so instead.

end
a[i] += r
end

result = a[r]
if result != 8007
raise "incorrect result"
end
end
Loading