diff --git a/benchmarks.yml b/benchmarks.yml index 038bf2d..65465a9 100644 --- a/benchmarks.yml +++ b/benchmarks.yml @@ -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 diff --git a/benchmarks/loops-times.rb b/benchmarks/loops-times.rb new file mode 100644 index 0000000..485fa89 --- /dev/null +++ b/benchmarks/loops-times.rb @@ -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 + end + a[i] += r + end + + result = a[r] + if result != 8007 + raise "incorrect result" + end +end