From d2652b7f9edf9f625075beab0c4eb3767fe03c35 Mon Sep 17 00:00:00 2001 From: Maxime Chevalier-Boisvert Date: Fri, 27 Sep 2024 17:13:54 -0400 Subject: [PATCH] Speed up the per-iteration time for longer benchmarks (#336) Many of our benchmarks have long per-iteration times but are just repeating the same computation over and over. Bring the per-iteration time below one second to speed up warm up and the overall benchmarking process. --- benchmarks/30k_ifelse.rb | 2 +- benchmarks/30k_methods.rb | 2 +- benchmarks/blurhash/benchmark.rb | 1 - benchmarks/fannkuchredux/benchmark.rb | 14 ++++++-------- benchmarks/fluentd/benchmark.rb | 2 +- benchmarks/graphql/benchmark.rb | 6 +++--- benchmarks/matmul.rb | 2 +- benchmarks/ruby-json/benchmark.rb | 2 +- benchmarks/ruby-xor.rb | 2 +- benchmarks/sudoku.rb | 15 +++------------ 10 files changed, 18 insertions(+), 30 deletions(-) diff --git a/benchmarks/30k_ifelse.rb b/benchmarks/30k_ifelse.rb index 4ea4b252..1a640197 100644 --- a/benchmarks/30k_ifelse.rb +++ b/benchmarks/30k_ifelse.rb @@ -240012,7 +240012,7 @@ def inc(x) require_relative '../harness/loader' -INTERNAL_ITRS = Integer(ENV.fetch("INTERNAL_ITRS", 600)) +INTERNAL_ITRS = Integer(ENV.fetch("INTERNAL_ITRS", 200)) run_benchmark(30) do INTERNAL_ITRS.times do diff --git a/benchmarks/30k_methods.rb b/benchmarks/30k_methods.rb index 6f35f98a..2eedbe6c 100644 --- a/benchmarks/30k_methods.rb +++ b/benchmarks/30k_methods.rb @@ -120009,7 +120009,7 @@ def inc() require_relative '../harness/loader' -INTERNAL_ITRS = Integer(ENV.fetch("INTERNAL_ITRS", 2000)) +INTERNAL_ITRS = Integer(ENV.fetch("INTERNAL_ITRS", 200)) run_benchmark(10) do INTERNAL_ITRS.times do diff --git a/benchmarks/blurhash/benchmark.rb b/benchmarks/blurhash/benchmark.rb index 91566828..7c82151d 100644 --- a/benchmarks/blurhash/benchmark.rb +++ b/benchmarks/blurhash/benchmark.rb @@ -79,7 +79,6 @@ def self.multiplyBasisFunction(xComponent, yComponent, width, height, rgb, bytes factors.set(yComponent, xComponent, 2, b * scale) end - def self.encode_int(value, length, destination) divisor = 83 ** (length - 1) diff --git a/benchmarks/fannkuchredux/benchmark.rb b/benchmarks/fannkuchredux/benchmark.rb index ffbd8469..b6641b11 100644 --- a/benchmarks/fannkuchredux/benchmark.rb +++ b/benchmarks/fannkuchredux/benchmark.rb @@ -59,15 +59,13 @@ def fannkuch(n) require_relative '../../harness/loader' run_benchmark(10) do - 5.times do - sum, flips = fannkuch(n) + sum, flips = fannkuch(n) - if sum != 8629 - raise RuntimeError, "incorrect sum: #{sum}" - end + if sum != 8629 + raise RuntimeError, "incorrect sum: #{sum}" + end - if flips != 30 - raise RuntimeError, "incorrect flips: #{flips}" - end + if flips != 30 + raise RuntimeError, "incorrect flips: #{flips}" end end diff --git a/benchmarks/fluentd/benchmark.rb b/benchmarks/fluentd/benchmark.rb index 15eaa19b..c503a653 100644 --- a/benchmarks/fluentd/benchmark.rb +++ b/benchmarks/fluentd/benchmark.rb @@ -18,7 +18,7 @@ "No local datasource found", ] ltsv = 1000.times.map { |i| "time:#{time + i} module:main.py level:DEBUG message:#{errors.sample}\n" }.join -ltsv *= 1000 +ltsv *= 250 # Prepare an LTSV parser parser = Fluent::Plugin::LabeledTSVParser.new diff --git a/benchmarks/graphql/benchmark.rb b/benchmarks/graphql/benchmark.rb index 89533f3a..3eb90e04 100644 --- a/benchmarks/graphql/benchmark.rb +++ b/benchmarks/graphql/benchmark.rb @@ -5,10 +5,10 @@ require "graphql" -file = File.read "negotiate.gql" +data = File.read "negotiate.gql" run_benchmark(10) do - 100.times do |i| - GraphQL.parse file + 10.times do |i| + GraphQL.parse data end end diff --git a/benchmarks/matmul.rb b/benchmarks/matmul.rb index ce119a77..ee396aef 100644 --- a/benchmarks/matmul.rb +++ b/benchmarks/matmul.rb @@ -32,7 +32,7 @@ def matmul(a, b) c end -n = 300 +n = 200 if ARGV.length > 0 n = ARGV[0].to_i end diff --git a/benchmarks/ruby-json/benchmark.rb b/benchmarks/ruby-json/benchmark.rb index 674b7d2a..96bc1787 100644 --- a/benchmarks/ruby-json/benchmark.rb +++ b/benchmarks/ruby-json/benchmark.rb @@ -143,4 +143,4 @@ def parse_item # https://github.com/openfootball/football.json/blob/master/2011-12/at.1.json source = IO.read("#{__dir__}/data.json") -run_benchmark(10) { 1000.times { JSONParser.new(source).parse } } +run_benchmark(10) { 100.times { JSONParser.new(source).parse } } diff --git a/benchmarks/ruby-xor.rb b/benchmarks/ruby-xor.rb index 0cad62f0..235dac8b 100644 --- a/benchmarks/ruby-xor.rb +++ b/benchmarks/ruby-xor.rb @@ -34,7 +34,7 @@ def ruby_xor!(a, b) b = 'this is also a long string with no useful contents yada yada daaaaaa' run_benchmark(20) do - for i in 0...100_000 + for i in 0...20_000 ruby_xor!(a.dup, b) end end diff --git a/benchmarks/sudoku.rb b/benchmarks/sudoku.rb index 2b90eb33..6c5475ef 100644 --- a/benchmarks/sudoku.rb +++ b/benchmarks/sudoku.rb @@ -213,18 +213,9 @@ def sd_solve(mr, mc, s) mr, mc = sd_genmat -n = 4 -if ARGV.length > 0 - n = ARGV[0].to_i -end - run_benchmark(20) do - i = 0 - while i < n - hard20.each do |line| - sd_solve(mr, mc, line) - # puts "" - end - i += 1 + hard20.each do |line| + sd_solve(mr, mc, line) + # puts "" end end