Skip to content

Commit d2652b7

Browse files
authored
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.
1 parent 33a3512 commit d2652b7

File tree

10 files changed

+18
-30
lines changed

10 files changed

+18
-30
lines changed

benchmarks/30k_ifelse.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240012,7 +240012,7 @@ def inc(x)
240012240012

240013240013
require_relative '../harness/loader'
240014240014

240015-
INTERNAL_ITRS = Integer(ENV.fetch("INTERNAL_ITRS", 600))
240015+
INTERNAL_ITRS = Integer(ENV.fetch("INTERNAL_ITRS", 200))
240016240016

240017240017
run_benchmark(30) do
240018240018
INTERNAL_ITRS.times do

benchmarks/30k_methods.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120009,7 +120009,7 @@ def inc()
120009120009

120010120010
require_relative '../harness/loader'
120011120011

120012-
INTERNAL_ITRS = Integer(ENV.fetch("INTERNAL_ITRS", 2000))
120012+
INTERNAL_ITRS = Integer(ENV.fetch("INTERNAL_ITRS", 200))
120013120013

120014120014
run_benchmark(10) do
120015120015
INTERNAL_ITRS.times do

benchmarks/blurhash/benchmark.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ def self.multiplyBasisFunction(xComponent, yComponent, width, height, rgb, bytes
7979
factors.set(yComponent, xComponent, 2, b * scale)
8080
end
8181

82-
8382
def self.encode_int(value, length, destination)
8483
divisor = 83 ** (length - 1)
8584

benchmarks/fannkuchredux/benchmark.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,13 @@ def fannkuch(n)
5959
require_relative '../../harness/loader'
6060

6161
run_benchmark(10) do
62-
5.times do
63-
sum, flips = fannkuch(n)
62+
sum, flips = fannkuch(n)
6463

65-
if sum != 8629
66-
raise RuntimeError, "incorrect sum: #{sum}"
67-
end
64+
if sum != 8629
65+
raise RuntimeError, "incorrect sum: #{sum}"
66+
end
6867

69-
if flips != 30
70-
raise RuntimeError, "incorrect flips: #{flips}"
71-
end
68+
if flips != 30
69+
raise RuntimeError, "incorrect flips: #{flips}"
7270
end
7371
end

benchmarks/fluentd/benchmark.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"No local datasource found",
1919
]
2020
ltsv = 1000.times.map { |i| "time:#{time + i} module:main.py level:DEBUG message:#{errors.sample}\n" }.join
21-
ltsv *= 1000
21+
ltsv *= 250
2222

2323
# Prepare an LTSV parser
2424
parser = Fluent::Plugin::LabeledTSVParser.new

benchmarks/graphql/benchmark.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
require "graphql"
77

8-
file = File.read "negotiate.gql"
8+
data = File.read "negotiate.gql"
99

1010
run_benchmark(10) do
11-
100.times do |i|
12-
GraphQL.parse file
11+
10.times do |i|
12+
GraphQL.parse data
1313
end
1414
end

benchmarks/matmul.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def matmul(a, b)
3232
c
3333
end
3434

35-
n = 300
35+
n = 200
3636
if ARGV.length > 0
3737
n = ARGV[0].to_i
3838
end

benchmarks/ruby-json/benchmark.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,4 @@ def parse_item
143143
# https://github.com/openfootball/football.json/blob/master/2011-12/at.1.json
144144
source = IO.read("#{__dir__}/data.json")
145145

146-
run_benchmark(10) { 1000.times { JSONParser.new(source).parse } }
146+
run_benchmark(10) { 100.times { JSONParser.new(source).parse } }

benchmarks/ruby-xor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def ruby_xor!(a, b)
3434
b = 'this is also a long string with no useful contents yada yada daaaaaa'
3535

3636
run_benchmark(20) do
37-
for i in 0...100_000
37+
for i in 0...20_000
3838
ruby_xor!(a.dup, b)
3939
end
4040
end

benchmarks/sudoku.rb

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -213,18 +213,9 @@ def sd_solve(mr, mc, s)
213213

214214
mr, mc = sd_genmat
215215

216-
n = 4
217-
if ARGV.length > 0
218-
n = ARGV[0].to_i
219-
end
220-
221216
run_benchmark(20) do
222-
i = 0
223-
while i < n
224-
hard20.each do |line|
225-
sd_solve(mr, mc, line)
226-
# puts ""
227-
end
228-
i += 1
217+
hard20.each do |line|
218+
sd_solve(mr, mc, line)
219+
# puts ""
229220
end
230221
end

0 commit comments

Comments
 (0)