Skip to content

Commit 2e2eb8b

Browse files
committed
Update some benchmarks to be ractor compatible
Ex: ./run_benchmarks sudoku --harness=ractor
1 parent df35185 commit 2e2eb8b

File tree

16 files changed

+140
-64
lines changed

16 files changed

+140
-64
lines changed

benchmarks.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ mail:
3434
psych-load:
3535
desc: psych-load repeatedly loads a small selection of YAML files taken from various OSS projects.
3636
category: headline
37+
ractor: true
3738
railsbench:
3839
desc: railsbench is a read-only tiny SQLite-backed Rails app, querying a small selection of .html.erb routes and JSON routes.
3940
category: headline
@@ -52,6 +53,7 @@ sequel:
5253
#
5354
binarytrees:
5455
desc: binarytrees from the Computer Language Benchmarks Game.
56+
ractor: true
5557
erubi:
5658
desc: erubi compiles a simple Erb template into a method with erubi, then times evaluating that method.
5759
etanni:
@@ -62,18 +64,21 @@ fluentd:
6264
desc: fluentd is a log collector, which parses logs in a server and forwards them to various destinations.
6365
graphql:
6466
desc: GraphQL gem parsing a large file, uses Racc which has some Ruby->native->Ruby calls
67+
ractor: true
6568
graphql-native:
6669
desc: GraphQL gem parsing a large file, but using a native parser
6770
lee:
6871
desc: lee is a circuit-board layout solver, deployed in a plausibly reality-like way
6972
nbody:
7073
desc: nbody from the Computer Language Benchmarks Game.
74+
ractor: true
7175
optcarrot:
7276
desc: optcarrot is a functional headless NES emulator, run on a specific game cartridge for a specific number of frames.
7377
rack:
7478
desc: test the performance of the Rack framework with barely any routing.
7579
ruby-json:
7680
desc: an optimized version of the json_pure gem's pure Ruby JSON parser.
81+
ractor: true
7782
rubyboy:
7883
desc: Rubyboy is a functional headless GameBoy emulator, run on a specific game cartridge for a specific number of frames.
7984
rubykon:
@@ -82,12 +87,16 @@ tinygql:
8287
desc: TinyGQL gem parsing a large file in pure Ruby
8388
nqueens:
8489
desc: solver for the N-Queens problem
90+
ractor: true
8591
sudoku:
8692
desc: sudoku solver
93+
ractor: true
8794
matmul:
8895
desc: matrix multiplication benchmark
96+
ractor: true
8997
blurhash:
9098
desc: blurhash (blurred preview image) calculation
99+
ractor: true
91100
protoboeuf:
92101
desc: protoboeuf (pure-Ruby protobuf) message decoding
93102
protoboeuf-encode:
@@ -100,6 +109,7 @@ protoboeuf-encode:
100109
desc: 30k_ifelse tests thousands of nested methods containing simple if/else statements.
101110
category: micro
102111
single_file: true
112+
ractor: true
103113
30k_methods:
104114
desc: 30k_methods tests thousands of nested method calls that mostly just call out to other single-call methods.
105115
category: micro
@@ -108,14 +118,17 @@ cfunc_itself:
108118
desc: cfunc_itself just calls the 'itself' method many, many times.
109119
category: micro
110120
single_file: true
121+
ractor: true
111122
fib:
112123
desc: Fib is a simple exponential-time recursive Fibonacci number generator.
113124
category: micro
114125
single_file: true
126+
ractor: true
115127
getivar:
116128
desc: getivar tests the performance of getting instance variable values.
117129
category: micro
118130
single_file: true
131+
ractor: true
119132
attr_accessor:
120133
desc: attr_accessor tests the performance of getting instance variable values via an attr_accessor imemo.
121134
category: micro
@@ -124,14 +137,17 @@ keyword_args:
124137
desc: keyword_args tests the performance of method calls with keyword arguments.
125138
category: micro
126139
single_file: true
140+
ractor: true
127141
respond_to:
128142
desc: respond_to tests the performance of the respond_to? method.
129143
category: micro
130144
single_file: true
145+
ractor: true
131146
object-new:
132147
desc: instantiate a new object in a loop to test allocation performance
133148
category: micro
134149
single_file: true
150+
ractor: true
135151
setivar:
136152
desc: setivar tests the performance of setting instance variable values.
137153
category: micro
@@ -144,19 +160,24 @@ setivar_young:
144160
desc: setivar_object tests the performance of setting instance variables to an object, to test write barrier speed on young objects.
145161
category: micro
146162
single_file: true
163+
ractor: true
147164
str_concat:
148165
desc: str_concat tests the performance of string concatenation in multiple different encodings.
149166
category: micro
150167
single_file: true
168+
ractor: true
151169
throw:
152170
desc: microbenchmark for the throw instruction and stack unwinding.
153171
category: micro
154172
single_file: true
173+
ractor: true
155174
ruby-xor:
156175
desc: pure-Ruby string XOR microbenchmark, analogous to xorcist C extension.
157176
category: micro
158177
single_file: true
178+
ractor: true
159179
loops-times:
160180
desc: nested loop Integer#times and array access microbenchmark
161181
category: micro
162182
single_file: true
183+
ractor: true

benchmarks/30k_ifelse.rb

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
require_relative '../harness/loader'
2+
if ENV["YJIT_BENCH_RACTOR_HARNESS"]
3+
eval_recv = Object.new
4+
eval_meth = :instance_eval
5+
else
6+
eval_recv = nil
7+
end
8+
19
def fun_l0_n0(x)
210
if (x < 1)
311
fun_l1_n310(x)
@@ -239998,23 +240006,29 @@ def fun_l29_n999(x)
239998240006
end
239999240007
end
240000240008

240001-
@a = 0
240002-
@b = 0
240003-
@c = 0
240004-
@d = 0
240005-
240006-
@count = 0
240007240009
def inc(x)
240008240010
@count += 1
240009240011
end
240010240012

240011-
@x = 0
240012-
240013-
require_relative '../harness/loader'
240014-
240015240013
INTERNAL_ITRS = Integer(ENV.fetch("INTERNAL_ITRS", 200))
240016240014

240017-
run_benchmark(30) do
240015+
main_obj = ENV["YJIT_BENCH_RACTOR_HARNESS"] ? eval_recv : nil
240016+
run_benchmark(30, ractor_args: [main_obj]) do |num_rs, selv|
240017+
if selv
240018+
recv = selv
240019+
recv_meth = :instance_eval
240020+
else
240021+
recv = 1
240022+
recv_meth = :times
240023+
end
240024+
recv.send(recv_meth) do
240025+
@a = 0
240026+
@b = 0
240027+
@c = 0
240028+
@d = 0
240029+
240030+
@count = 0
240031+
@x = 0
240018240032
INTERNAL_ITRS.times do
240019240033
@x = (@x < 1)? 1:0
240020240034
fun_l0_n0(@x)
@@ -241017,5 +241031,6 @@ def inc(x)
241017241031
fun_l0_n997(@x)
241018241032
fun_l0_n998(@x)
241019241033
fun_l0_n999(@x)
241034+
end
241020241035
end
241021241036
end

benchmarks/binarytrees/benchmark.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@ def bottom_up_tree(depth)
1616
[bottom_up_tree(depth), bottom_up_tree(depth)]
1717
end
1818

19-
max_depth = 14
20-
min_depth = 4
19+
MAX_DEPTH = 14
20+
MIN_DEPTH = 4
2121

22-
max_depth = min_depth + 2 if min_depth + 2 > max_depth
23-
stretch_depth = max_depth + 1
22+
MAX_DEPTH = MIN_DEPTH + 2 if MIN_DEPTH + 2 > MAX_DEPTH
23+
STRETCH_DEPTH = MAX_DEPTH + 1
2424

2525
require_relative '../../harness/loader'
2626

2727
run_benchmark(60) do
28+
max_depth = MAX_DEPTH
29+
min_depth = MIN_DEPTH
30+
stretch_depth = STRETCH_DEPTH
2831
stretch_tree = bottom_up_tree(stretch_depth)
2932
stretch_tree = nil
3033

benchmarks/blurhash/benchmark.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def [](from, len)
4646
end
4747
end
4848

49-
CHARACTERS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$%*+,-.:;=?@[]^_{|}~".bytes
49+
CHARACTERS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$%*+,-.:;=?@[]^_{|}~".bytes.freeze
5050

5151
def self.sRGBToLinear(value)
5252
v = value.to_f / 255
@@ -176,8 +176,8 @@ def blurHashForPixels(xComponents, yComponents, width, height, rgb, bytesPerRow)
176176

177177
FILE = File.join(__dir__, "test.bin")
178178

179-
array = File.read(FILE).bytes
179+
Ractor.make_shareable(ARRAY = File.read(FILE).bytes)
180180

181181
run_benchmark(10) do
182-
Blurhash.encode_rb(204, 204, array)
182+
Blurhash.encode_rb(204, 204, ARRAY)
183183
end

benchmarks/getivar.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ def get_value_loop
3232
end
3333
end
3434

35-
obj = TheClass.new
35+
OBJ = TheClass.new.freeze
3636

3737
run_benchmark(850) do
38-
obj.get_value_loop
38+
OBJ.get_value_loop
3939
end

benchmarks/hexapdf/benchmark.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@
1818

1919
Dir["/tmp/hexapdf-result*.pdf"].each { |file| FileUtils.rm file }
2020

21-
index = 0
21+
if ENV["YJIT_BENCH_RACTOR_HARNESS"]
22+
Ractor.make_shareable(HexaPDF::DefaultDocumentConfiguration)
23+
Ractor.make_shareable(HexaPDF::GlobalConfiguration)
24+
# TODO... still doesn't work
25+
end
26+
27+
iter = 0
28+
2229
run_benchmark(10) do
2330
## TTF benchmark (v. slow)
2431
#HexaPDF::Composer.create(OUT_FILENAME, page_size: [0, 0, WIDTH, HEIGHT], margin: 0) do |pdf|
@@ -28,8 +35,8 @@
2835
#end
2936

3037
# Non-TTF benchmark
31-
index += 1
32-
out_filename = "/tmp/hexapdf-result-#{ "%03d" % index }.pdf"
38+
iter += 1
39+
out_filename = "/tmp/hexapdf-result-#{ "%03d" % iter }.pdf"
3340

3441

3542
composer = HexaPDF::Composer.new(page_size: [0, 0, WIDTH, HEIGHT], margin: 0)

benchmarks/loops-times.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
require_relative '../harness/loader'
22

33
# Fix these values for determinism
4-
u = 5
5-
r = 7
4+
U = 5
5+
R = 7
66

77
run_benchmark(10) do
88
a = Array.new(10000, 0)
99

1010
4_000.times do |i|
1111
4_000.times do |j|
12-
a[i] += j % u
12+
a[i] += J % U
1313
end
14-
a[i] += r
14+
a[i] += R
1515
end
1616

17-
result = a[r]
17+
result = a[R]
1818
if result != 8007
1919
raise "incorrect result"
2020
end

benchmarks/matmul.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ def matmul(a, b)
3737
n = ARGV[0].to_i
3838
end
3939
n = n / 2 * 2
40+
N = n
4041

4142
run_benchmark(20) do
42-
a = matgen(n)
43-
b = matgen(n)
43+
a = matgen(N)
44+
b = matgen(N)
4445
c = matmul(a, b)
4546
# puts c[n / 2][n / 2]
4647
end

benchmarks/nbody/benchmark.rb

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# modified by Jesse Millikan
66
# modified by Yusuke Endoh
77

8+
require_relative '../../harness/loader'
9+
810
SOLAR_MASS = 4 * Math::PI**2
911
DAYS_PER_YEAR = 365.24
1012

@@ -129,18 +131,27 @@ def offset_momentum(bodies)
129131

130132
offset_momentum(BODIES)
131133

132-
n = 20000
133-
nbodies = BODIES.size
134-
dt = 0.01
135-
136-
require_relative '../../harness/loader'
134+
N = 20000
135+
NBODIES = BODIES.size
136+
if ENV["YJIT_BENCH_RACTOR_HARNESS"]
137+
Ractor.make_shareable(BODIES)
138+
end
139+
DT = 0.01
137140

138141
run_benchmark(200) do
142+
nbodies = NBODIES
143+
n = N
144+
dt = DT
145+
if ENV["YJIT_BENCH_RACTOR_HARNESS"]
146+
bodies = ractor_deep_dup(BODIES)
147+
else
148+
bodies = BODIES
149+
end
139150
n.times do
140151
i = 0
141152
while i < nbodies
142-
b = BODIES[i]
143-
b.move_from_i(BODIES, nbodies, dt, i + 1)
153+
b = bodies[i]
154+
b.move_from_i(bodies, nbodies, dt, i + 1)
144155
i += 1
145156
end
146157
end

benchmarks/nqueens.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ def nq_solve(n)
3636
m
3737
end
3838

39-
n = 10
39+
N = 10
4040
if ARGV.length > 0
41-
n = ARGV[0].to_i
41+
N = ARGV[0].to_i
4242
end
4343

4444
run_benchmark(40) do
4545
10.times do
46-
nq_solve(n)
46+
nq_solve(N)
4747
end
4848
end

0 commit comments

Comments
 (0)