Skip to content

Commit eb606d6

Browse files
committed
Movel all hardness to a single directory
Use file based harness instead of directory based harness
1 parent 59333fb commit eb606d6

18 files changed

+83
-53
lines changed

README.md

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -211,22 +211,38 @@ This file will then be passed to the underlying Ruby interpreter with
211211

212212
## Harnesses
213213

214-
You can find several test harnesses in this repository:
214+
You can find several test harnesses in the `harness/` directory:
215215

216-
* harness - the normal default harness, with duration controlled by warmup iterations and time/count limits
217-
* harness-bips - a harness that measures iterations/second until stable
218-
* harness-continuous - a harness that adjusts the batch sizes of iterations to run in stable iteration size batches
219-
* harness-once - a simplified harness that simply runs once
220-
* harness-perf - a simplified harness that runs for exactly the hinted number of iterations
221-
* harness-stackprof - a harness to profile the benchmark with stackprof
222-
* harness-stats - count method calls and loop iterations
223-
* harness-vernier - a harness to profile the benchmark with vernier
224-
* harness-warmup - a harness which runs as long as needed to find warmed up (peak) performance
216+
* `harness` - the normal default harness, with duration controlled by warmup iterations and time/count limits
217+
* `bips` - a harness that measures iterations/second until stable
218+
* `continuous` - a harness that adjusts the batch sizes of iterations to run in stable iteration size batches
219+
* `once` - a simplified harness that simply runs once
220+
* `perf` - a simplified harness that runs for exactly the hinted number of iterations
221+
* `stackprof` - a harness to profile the benchmark with stackprof
222+
* `stats` - count method calls and loop iterations
223+
* `vernier` - a harness to profile the benchmark with vernier
224+
* `warmup` - a harness which runs as long as needed to find warmed up (peak) performance
225+
* `chain` - a harness to chain multiple harnesses together
226+
* `mplr` - a harness for multiple iterations with time limits
225227

226-
To use it, run a benchmark script directly, specifying a harness directory with `-I`:
228+
To use a specific harness, run a benchmark script directly with `-I` to add the harness directory to the load path, and `-r` to require the specific harness:
227229

228230
```
231+
# Use default harness
229232
ruby -Iharness benchmarks/railsbench/benchmark.rb
233+
234+
# Use the 'once' harness
235+
ruby -Iharness -ronce benchmarks/railsbench/benchmark.rb
236+
237+
# Use the 'perf' harness
238+
ruby -Iharness -rperf benchmarks/railsbench/benchmark.rb
239+
```
240+
241+
When using `run_benchmarks.rb`, you can specify a harness with the `--harness` option:
242+
243+
```
244+
./run_benchmarks.rb --harness=once
245+
./run_benchmarks.rb --harness=perf
230246
```
231247

232248
There is also a robust but complex CI harness in [the yjit-metrics repo](https://github.com/Shopify/yjit-metrics).
@@ -265,10 +281,10 @@ If `PERF` environment variable is present, it starts the perf subcommand after w
265281

266282
```sh
267283
# Use `perf record` for both warmup and benchmark
268-
perf record ruby --yjit-perf=map -Iharness-perf benchmarks/railsbench/benchmark.rb
284+
perf record ruby --yjit-perf=map -Iharness -rperf benchmarks/railsbench/benchmark.rb
269285

270286
# Use `perf record` only for benchmark
271-
PERF=record ruby --yjit-perf=map -Iharness-perf benchmarks/railsbench/benchmark.rb
287+
PERF=record ruby --yjit-perf=map -Iharness -rperf benchmarks/railsbench/benchmark.rb
272288
```
273289

274290
This is the only harness that uses `run_benchmark`'s argument, `num_itrs_hint`.

harness-bips/harness.rb renamed to harness/bips.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require 'benchmark/ips'
2-
require_relative "../harness/harness-common"
2+
require_relative "harness-common"
33

44
puts RUBY_DESCRIPTION
55

harness-chain/harness.rb renamed to harness/chain.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require_relative '../harness/harness-common'
1+
require_relative 'harness-common'
22

33
# Ex: HARNESS_CHAIN="vernier,ractor"
44
# Wraps the ractor harness in ther vernier harness
@@ -10,7 +10,7 @@
1010
end
1111

1212
if CHAIN.include?("vernier") && CHAIN.last != "vernier"
13-
require_relative "../harness/harness-extra"
13+
require_relative "harness-extra"
1414
def run_enough_to_profile(n, **kwargs, &block)
1515
block.call
1616
end
@@ -30,12 +30,12 @@ def self.method_added(name)
3030
def run_benchmark(n, **kwargs, &block)
3131
CHAIN.each do |h|
3232
begin
33-
path = "../harness-#{h}/harness"
33+
path = "#{h}"
3434
$current_harness = h
3535
require_relative path
3636
rescue LoadError => e
3737
if e.path == path
38-
$stderr.puts "Can't find harness harness-#{h}/harness.rb. Exiting."
38+
$stderr.puts "Can't find harness #{h}.rb in harness/. Exiting."
3939
exit 1
4040
end
4141
raise

harness-continuous/harness.rb renamed to harness/continuous.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require_relative "../harness/harness-common"
1+
require_relative "harness-common"
22

33
puts RUBY_DESCRIPTION
44

harness/loader.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
# Use harness/harness.rb by default. You can change it with -I option.
2-
# i.e. ruby -Iharness benchmarks/railsbench/benchmark.rb
1+
# Use harness/harness.rb by default. You can change it with -I and -r options.
2+
# Examples:
3+
# ruby -Iharness benchmarks/railsbench/benchmark.rb # uses harness/harness.rb
4+
# ruby -Iharness -ronce benchmarks/railsbench/benchmark.rb # uses harness/once.rb
5+
# ruby -Iharness -rractor benchmarks/railsbench/benchmark.rb # uses harness/ractor.rb
36
retries = 0
47
begin
58
require "harness"

harness-mplr/harness.rb renamed to harness/mplr.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require 'benchmark'
2-
require_relative "../harness/harness-common"
2+
require_relative "harness-common"
33

44
# Minimum number of benchmarking iterations
55
MAX_BENCH_ITRS = Integer(ENV.fetch('MAX_BENCH_ITRS', 1000))

harness-once/harness.rb renamed to harness/once.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Intended only for checking whether the benchmark can set itself up properly
66
# and can run to completion.
77

8-
require_relative '../harness/harness-common'
8+
require_relative 'harness-common'
99

1010
def run_benchmark(_hint, **)
1111
yield

harness-perf/harness.rb renamed to harness/perf.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
# This is a relatively minimal harness meant for use with Linux perf(1).
44
# Example usage:
55
#
6-
# $ PERF='record -e cycles' ruby -Iharness-perf benchmarks/fib.rb
6+
# $ PERF='record -e cycles' ruby -Iharness -rperf benchmarks/fib.rb
77
#
88
# When recording with perf(1), make sure the benchmark runs long enough; you
99
# can tweak the MIN_BENCH_ITRS environment variable to lengthen the run. A race
1010
# condition is possible where the benchmark finishes before the perf(1)
1111
# subprocess has a chance to attach, in which case perf outputs no profile.
1212

13-
require_relative "../harness/harness-common"
13+
require_relative "harness-common"
1414

1515
# Run $WARMUP_ITRS or 10 iterations of a given block. Then run $MIN_BENCH_ITRS
1616
# or `num_itrs_int` iterations of the block, attaching a perf command to the

harness-ractor/harness.rb renamed to harness/ractor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
2-
require_relative '../harness/harness-common'
2+
require_relative 'harness-common'
33

44
Warning[:experimental] = false
55
ENV["RUBY_BENCH_RACTOR_HARNESS"] = "1"

harness-stackprof/harness.rb renamed to harness/stackprof.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
# Profile the benchmark (ignoring initialization code) with stackprof.
44
# Customize stackprof options with an env var of STACKPROF_OPTS='key:value,...'.
55
# Usage:
6-
# STACKPROF_OPTS='mode:object' MIN_BENCH_TIME=0 MIN_BENCH_ITRS=1 ruby -v -I harness-stackprof benchmarks/.../benchmark.rb
7-
# STACKPROF_OPTS='mode:cpu,interval:10' MIN_BENCH_TIME=1 MIN_BENCH_ITRS=10 ruby -v -I harness-stackprof benchmarks/.../benchmark.rb
6+
# STACKPROF_OPTS='mode:object' MIN_BENCH_TIME=0 MIN_BENCH_ITRS=1 ruby -v -Iharness -rstackprof benchmarks/.../benchmark.rb
7+
# STACKPROF_OPTS='mode:cpu,interval:10' MIN_BENCH_TIME=1 MIN_BENCH_ITRS=10 ruby -v -Iharness -rstackprof benchmarks/.../benchmark.rb
88

9-
require_relative "../harness/harness-common"
10-
require_relative "../harness/harness-extra"
9+
require_relative "harness-common"
10+
require_relative "harness-extra"
1111

1212
ensure_global_gem("stackprof")
1313

0 commit comments

Comments
 (0)