Skip to content

Commit 39d39bb

Browse files
committed
Movel all hardness to a single directory
Use file based harness instead of directory based harness
1 parent 28aca5b commit 39d39bb

18 files changed

+83
-53
lines changed

README.md

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

185185
## Harnesses
186186

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

189-
* harness - the normal default harness, with duration controlled by warmup iterations and time/count limits
190-
* harness-bips - a harness that measures iterations/second until stable
191-
* harness-continuous - a harness that adjusts the batch sizes of iterations to run in stable iteration size batches
192-
* harness-once - a simplified harness that simply runs once
193-
* harness-perf - a simplified harness that runs for exactly the hinted number of iterations
194-
* harness-stackprof - a harness to profile the benchmark with stackprof
195-
* harness-stats - count method calls and loop iterations
196-
* harness-vernier - a harness to profile the benchmark with vernier
197-
* harness-warmup - a harness which runs as long as needed to find warmed up (peak) performance
189+
* `harness` - the normal default harness, with duration controlled by warmup iterations and time/count limits
190+
* `bips` - a harness that measures iterations/second until stable
191+
* `continuous` - a harness that adjusts the batch sizes of iterations to run in stable iteration size batches
192+
* `once` - a simplified harness that simply runs once
193+
* `perf` - a simplified harness that runs for exactly the hinted number of iterations
194+
* `stackprof` - a harness to profile the benchmark with stackprof
195+
* `stats` - count method calls and loop iterations
196+
* `vernier` - a harness to profile the benchmark with vernier
197+
* `warmup` - a harness which runs as long as needed to find warmed up (peak) performance
198+
* `chain` - a harness to chain multiple harnesses together
199+
* `mplr` - a harness for multiple iterations with time limits
198200

199-
To use it, run a benchmark script directly, specifying a harness directory with `-I`:
201+
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:
200202

201203
```
204+
# Use default harness
202205
ruby -Iharness benchmarks/railsbench/benchmark.rb
206+
207+
# Use the 'once' harness
208+
ruby -Iharness -ronce benchmarks/railsbench/benchmark.rb
209+
210+
# Use the 'perf' harness
211+
ruby -Iharness -rperf benchmarks/railsbench/benchmark.rb
212+
```
213+
214+
When using `run_benchmarks.rb`, you can specify a harness with the `--harness` option:
215+
216+
```
217+
./run_benchmarks.rb --harness=once
218+
./run_benchmarks.rb --harness=perf
203219
```
204220

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

239255
```sh
240256
# Use `perf record` for both warmup and benchmark
241-
perf record ruby --yjit-perf=map -Iharness-perf benchmarks/railsbench/benchmark.rb
257+
perf record ruby --yjit-perf=map -Iharness -rperf benchmarks/railsbench/benchmark.rb
242258

243259
# Use `perf record` only for benchmark
244-
PERF=record ruby --yjit-perf=map -Iharness-perf benchmarks/railsbench/benchmark.rb
260+
PERF=record ruby --yjit-perf=map -Iharness -rperf benchmarks/railsbench/benchmark.rb
245261
```
246262

247263
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)