Skip to content

Commit df35185

Browse files
committed
Improve ractor harness and update other harnesses to be compatible
1 parent e20641b commit df35185

File tree

12 files changed

+70
-23
lines changed

12 files changed

+70
-23
lines changed

harness-bips/harness.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
puts RUBY_DESCRIPTION
55

6-
def run_benchmark(_, &block)
6+
def run_benchmark(_, **, &block)
77
Benchmark.ips do |x|
88
x.report 'benchmark', &block
99
end
10+
return_results([], [1.0])
1011
end

harness-chain/harness.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require_relative '../harness/harness-common'
2+
3+
CHAIN = ENV['HARNESS_CHAIN'].to_s.split(',')
4+
CHAIN.reject! { |el| el.to_s.strip.empty? }
5+
if CHAIN.size < 2
6+
$stderr.puts "You need to chain at least 2 harnesses. Exiting."
7+
exit 1
8+
end
9+
10+
def run_benchmark(n, **kwargs, &block)
11+
CHAIN.each do |h|
12+
begin
13+
path = "../harness-#{h}/harness"
14+
require_relative path
15+
rescue LoadError => e
16+
if e.path == path
17+
$stderr.puts "Can't find harness harness-#{h}/harness.rb. Exiting."
18+
exit 1
19+
end
20+
raise
21+
end
22+
end
23+
end

harness-continuous/harness.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22

33
puts RUBY_DESCRIPTION
44

5-
def run_benchmark(_)
5+
def run_benchmark(n, **, &blk)
66
iterations = 1
77
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
88

99
loop do
10-
iterations.times do
11-
yield
12-
end
10+
iterations.times(&blk)
1311

1412
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
1513
round_time = end_time - start_time

harness-mplr/harness.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
puts RUBY_DESCRIPTION
1111

1212
# Takes a block as input
13-
def run_benchmark(_num_itrs_hint)
13+
def run_benchmark(_num_itrs_hint, **, &blk)
1414
times = []
1515
total_time = 0
1616
num_itrs = 0

harness-once/harness.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
require_relative '../harness/harness-common'
99

10-
def run_benchmark(_hint)
10+
def run_benchmark(_hint, **)
1111
yield
1212
return_results([], [0.001]) # bogus timing
1313
end

harness-perf/harness.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# the number of benchmark iterations. For example, if the default harness runs
2121
# 10 benchmark iterations (after 15 warmup iterations) for a benchmark with
2222
# the default MIN_BENCH_TIME, the benchmark should have 10 as `num_itrs_hint`.
23-
def run_benchmark(num_itrs_hint)
23+
def run_benchmark(num_itrs_hint, **, &blk)
2424
warmup_itrs = Integer(ENV.fetch('WARMUP_ITRS', 10))
2525
bench_itrs = Integer(ENV.fetch('MIN_BENCH_ITRS', num_itrs_hint))
2626

harness-ractor/harness.rb

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1+
# frozen_string_literal: true
12
require_relative '../harness/harness-common'
23

34
Warning[:experimental] = false
45
ENV["YJIT_BENCH_RACTOR_HARNESS"] = "1"
56

6-
RACTORS = [
7+
default_ractors = [
78
0, # without ractor
89
1, 2, 4, 6, 8, 12, 16, 32
9-
].freeze
10+
]
11+
if rs = ENV["YJIT_BENCH_RACTORS"]
12+
rs = rs.split(",").map(&:to_i) # If you want to include 0, you have to specify
13+
rs = rs.sort.uniq
14+
if rs.any?
15+
ractors = rs
16+
end
17+
end
18+
RACTORS = (ractors || default_ractors).freeze
1019

1120
unless Ractor.method_defined?(:join)
1221
class Ractor
@@ -32,25 +41,23 @@ def run_benchmark(num_itrs_hint, ractor_args: [], &block)
3241
args = if ractor_args.empty?
3342
[]
3443
else
35-
Ractor.make_shareable(ractor_args, copy: true)
44+
ractor_deep_dup(ractor_args)
3645
end
37-
block.call *args
46+
block.call *([0] + args)
3847
i += 1
3948
end
4049

4150
blk = Ractor.make_shareable(block)
4251
RACTORS.each do |rs|
4352
num_itrs = 0
4453
while num_itrs < bench_itrs
45-
# copy args before we begin measuring the time so it's not included
46-
shareable_args = ractor_args.empty? ? [] : Ractor.make_shareable(ractor_args, copy: true)
4754
before = Process.clock_gettime(Process::CLOCK_MONOTONIC)
4855
if rs.zero?
49-
block.call *shareable_args
56+
block.call *([rs] + ractor_deep_dup(ractor_args))
5057
else
5158
rs_list = []
5259
rs.times do
53-
rs_list << Ractor.new(*shareable_args, &block)
60+
rs_list << Ractor.new(*([rs] + ractor_args), &block)
5461
end
5562
while rs_list.any?
5663
r, _obj = Ractor.select(*rs_list)
@@ -68,4 +75,22 @@ def run_benchmark(num_itrs_hint, ractor_args: [], &block)
6875
return_results([], stats.values.flatten)
6976
end
7077

78+
def ractor_deep_dup(args)
79+
if Array === args
80+
ret = []
81+
args.each do |el|
82+
ret << ractor_deep_dup(el)
83+
end
84+
ret
85+
elsif Hash === args
86+
ret = {}
87+
args.each do |k,v|
88+
ret[ractor_deep_dup(k)] = ractor_deep_dup(v)
89+
end
90+
ret
91+
else
92+
args.dup
93+
end
94+
end
95+
7196
Ractor.make_shareable(self)

harness-stackprof/harness.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def stackprof_opts
6161
opts
6262
end
6363

64-
def run_benchmark(n, &block)
64+
def run_benchmark(n, **, &block)
6565
require "stackprof"
6666

6767
opts = stackprof_opts

harness-stats/harness.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Using Module#prepend to enable TracePoint right before #run_benchmark
44
# while also reusing the original implementation.
55
self.singleton_class.prepend Module.new {
6-
def run_benchmark(*)
6+
def run_benchmark(n, **, &block)
77
frames = []
88
c_calls = Hash.new { 0 }
99
c_blocks = Hash.new { 0 }
@@ -43,7 +43,7 @@ def run_benchmark(*)
4343

4444
method_trace.enable
4545
block_trace.enable
46-
super
46+
super(n, &block)
4747
ensure
4848
block_trace.disable
4949
method_trace.disable

harness-vernier/harness.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
ensure_global_gem("vernier")
1313
ensure_global_gem_exe("profile-viewer")
1414

15-
def run_benchmark(n, &block)
15+
def run_benchmark(n, **kwargs, &block)
1616
require "vernier"
1717

1818
out = output_file_path(ext: "json")
1919
Vernier.profile(out: out) do
20-
run_enough_to_profile(n, &block)
20+
run_enough_to_profile(n, **kwargs, &block)
2121
end
2222

2323
puts "Vernier profile:\n#{out}"

0 commit comments

Comments
 (0)