Skip to content

Commit 9ba2e2c

Browse files
committed
[GR-26172] Add a benchmark-interface backend to run a fixed number of iterations
PullRequest: truffleruby/2020
2 parents c051dff + d1659e7 commit 9ba2e2c

File tree

6 files changed

+62
-5
lines changed

6 files changed

+62
-5
lines changed

bench/benchmark-interface/lib/benchmark-interface.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
require 'benchmark-interface/frontends/mri'
1313
require 'benchmark-interface/backends/simple'
1414
require 'benchmark-interface/backends/stable'
15+
require 'benchmark-interface/backends/fixed-iterations'
1516
require 'benchmark-interface/backends/benchmark'
1617
require 'benchmark-interface/backends/bips'
1718
require 'benchmark-interface/backends/bench9000'
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. This
2+
# code is released under a tri EPL/GPL/LGPL license. You can use it,
3+
# redistribute it and/or modify it under the terms of the:
4+
#
5+
# Eclipse Public License version 2.0, or
6+
# GNU General Public License version 2, or
7+
# GNU Lesser General Public License version 2.1.
8+
9+
module BenchmarkInterface
10+
module Backends
11+
module FixedIterations
12+
13+
def self.get_time
14+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
15+
end
16+
17+
def self.run(benchmark_set, names, options)
18+
print_iterations = options['--iterations']
19+
elapsed = options['--elapsed']
20+
print_ips = options['--ips']
21+
22+
fixed_iterations = options['--fixed-iterations'].sort
23+
total_iterations = fixed_iterations.last
24+
25+
benchmark_set.benchmarks(names).each do |benchmark|
26+
puts benchmark.name
27+
block = benchmark.block
28+
29+
next_iter = fixed_iterations.shift
30+
start_time = get_time
31+
(1..total_iterations).each do |iter|
32+
block.call
33+
34+
if iter == next_iter
35+
since_start = get_time - start_time
36+
puts iter if print_iterations
37+
puts since_start if elapsed
38+
puts iter / since_start if print_ips
39+
40+
next_iter = fixed_iterations.shift
41+
end
42+
end
43+
end
44+
end
45+
46+
end
47+
end
48+
end

bench/benchmark-interface/lib/benchmark-interface/backends/simple.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ def self.run(benchmark_set, names, options)
6161
# can print an ips and adjust for the next round to try to make
6262
# it take a second.
6363
ips = iterations / round_time
64-
puts get_time - start_time if elapsed
6564
puts iterations if print_iterations
65+
puts get_time - start_time if elapsed
6666
puts ips * inner_iterations
6767
iterations = (ips * freq).to_i
6868
end

bench/benchmark-interface/lib/benchmark-interface/backends/stable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def self.run(benchmark_set, names, options)
3030
round_time = Time.now - start_round_time
3131

3232
ips = 1 / round_time
33-
puts Time.now - start_time if elapsed
3433
puts 1 if print_iterations
34+
puts Time.now - start_time if elapsed
3535
puts ips * inner_iterations
3636
end
3737
end

bench/benchmark-interface/lib/benchmark-interface/run.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ def self.run(args)
3030
'--freq' => 1,
3131
'--elapsed' => false,
3232
'--iterations' => false,
33+
'--ips' => false,
34+
'--fixed-iterations' => [],
3335
'--log' => nil,
3436
'--tag' => [],
3537
'--prop' => {}
@@ -49,6 +51,9 @@ def self.run(args)
4951
backend = BenchmarkInterface::Backends::Simple
5052
when '--stable'
5153
backend = BenchmarkInterface::Backends::Stable
54+
when '--fixed-iterations'
55+
backend = BenchmarkInterface::Backends::FixedIterations
56+
options[arg] = args[n += 1].split(',').map { |iter| Integer(iter) }
5257
when '--bips'
5358
backend = BenchmarkInterface::Backends::Bips
5459
when '--bm'
@@ -72,6 +77,8 @@ def self.run(args)
7277
n += 1
7378
when '--elapsed'
7479
options[arg] = true
80+
when '--ips'
81+
options[arg] = true
7582
when '--log'
7683
options[arg] = args[n + 1]
7784
n += 1
@@ -148,9 +155,10 @@ def self.help
148155
puts ' list list benchmarks available in the files'
149156
puts
150157
puts 'Backends:'
151-
puts ' --simple'
158+
puts ' --simple (default)'
152159
puts ' --stable'
153-
puts ' --bips (default)'
160+
puts ' --fixed-iterations ITERS1,ITERS2,...'
161+
puts ' --bips'
154162
puts ' --bm'
155163
puts ' --bmbm'
156164
puts ' --bench9000'

mx.truffleruby/mx_truffleruby_benchmark.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ def runBenchmark(self, benchmark, bmSuiteArgs):
287287
lines = out.data.split('\n')[1:-1]
288288

289289
data = self.filterLines(lines)
290-
elapsed = [d for n, d in enumerate(data) if n % 3 == 0]
290+
elapsed = [d for n, d in enumerate(data) if n % 3 == 1]
291291
samples = [d for n, d in enumerate(data) if n % 3 == 2]
292292

293293
if lines[-1] == 'optimised away':

0 commit comments

Comments
 (0)