Skip to content

Commit 01c0eaf

Browse files
committed
make more benchmarks ractor friendly
1 parent 607cd5b commit 01c0eaf

File tree

6 files changed

+30
-14
lines changed

6 files changed

+30
-14
lines changed

benchmarks.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ etanni:
6060
desc: etanni is an older, extremely simple template-lang format that basically turns your template into an "eval" with a lot of heredocs.
6161
fannkuchredux:
6262
desc: fannkuchredux from the Computer Language Benchmarks Game.
63+
ractor: true
6364
fluentd:
6465
desc: fluentd is a log collector, which parses logs in a server and forwards them to various destinations.
6566
graphql:
@@ -81,8 +82,10 @@ ruby-json:
8182
ractor: true
8283
rubyboy:
8384
desc: Rubyboy is a functional headless GameBoy emulator, run on a specific game cartridge for a specific number of frames.
85+
ractor: true
8486
rubykon:
8587
desc: Ruby solver for Go (the boardgame.) Runs many iterations forward from an initial starting board.
88+
ractor: true
8689
tinygql:
8790
desc: TinyGQL gem parsing a large file in pure Ruby
8891
nqueens:
@@ -99,8 +102,10 @@ blurhash:
99102
ractor: true
100103
protoboeuf:
101104
desc: protoboeuf (pure-Ruby protobuf) message decoding
105+
ractor: true
102106
protoboeuf-encode:
103107
desc: protoboeuf (pure-Ruby protobuf) message encoding
108+
ractor: true
104109

105110
#
106111
# MicroBenchmarks

benchmarks/fannkuchredux/benchmark.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ def fannkuch(n)
5454
end
5555

5656
#n = (ARGV[0] || 1).to_i
57-
n = 9 # Benchmarks Game uses n = 12, but it's too slow
57+
N = 9 # Benchmarks Game uses n = 12, but it's too slow
5858

5959
require_relative '../../harness/loader'
6060

6161
run_benchmark(10) do
62-
sum, flips = fannkuch(n)
62+
sum, flips = fannkuch(N)
6363

6464
if sum != 8629
6565
raise RuntimeError, "incorrect sum: #{sum}"

benchmarks/protoboeuf-encode/benchmark.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
Dir.chdir __dir__
77
fake_msg_bins = Marshal.load(File.binread('encoded_msgs.bin'))
8-
lots = fake_msg_bins.map { |bin| ProtoBoeuf::ParkingLot.decode bin }
8+
LOTS = Ractor.make_shareable(fake_msg_bins.map { |bin| ProtoBoeuf::ParkingLot.decode bin })
99

1010
run_benchmark(20) do
11-
lots.each { |lot| ProtoBoeuf::ParkingLot.encode lot }
11+
LOTS.each { |lot| ProtoBoeuf::ParkingLot.encode lot }
1212
end

benchmarks/protoboeuf/benchmark.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
require_relative 'benchmark_pb'
55

66
Dir.chdir __dir__
7-
fake_msg_bins = Marshal.load(File.binread('encoded_msgs.bin'))
7+
FAKE_MSG_BINS = Ractor.make_shareable(Marshal.load(File.binread('encoded_msgs.bin')))
88

99
run_benchmark(20) do
10-
fake_msg_bins.each { |bin| ProtoBoeuf::ParkingLot.decode bin }
10+
FAKE_MSG_BINS.each { |bin| ProtoBoeuf::ParkingLot.decode bin }
1111
end

benchmarks/rubyboy/benchmark.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,21 @@
1111
require 'rubyboy/emulator_headless'
1212

1313
# The rom is included in the gem in a sibling directory to the rubyboy code.
14-
rom_path = File.expand_path("../../roms/tobu.gb", $".detect { |x| x.end_with?("/rubyboy/emulator_headless.rb") })
14+
ROM_PATH = File.expand_path("../../roms/tobu.gb", $".detect { |x| x.end_with?("/rubyboy/emulator_headless.rb") }).freeze
1515

1616
# A count of 500 produces results similar to our optcarrot benchmark.
1717
# It's possible there is a number that produces a consistent benchmark without
1818
# needing to re-initialize but not sure how to determine that.
19-
count = 500
19+
COUNT = 500
20+
21+
Ractor.make_shareable(Rubyboy::ApuChannels::Channel1::WAVE_DUTY)
22+
Ractor.make_shareable(Rubyboy::ApuChannels::Channel2::WAVE_DUTY)
2023

2124
run_benchmark(200) do
2225
# Results are much more consistent if we re-initialize each time.
2326
# Reusing the same eumlator increases stddev by 65x.
24-
emulator = Rubyboy::EmulatorHeadless.new(rom_path)
25-
count.times do
27+
emulator = Rubyboy::EmulatorHeadless.new(ROM_PATH)
28+
COUNT.times do
2629
emulator.step
2730
end
2831
end

benchmarks/rubykon/benchmark.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,17 @@
1010
# return the same stable best_move, even for identical initial board state and number of iterations.
1111

1212
ITERATIONS = 100
13-
game_state = Rubykon::GameState.new Rubykon::Game.new(19)
14-
mcts = MCTS::MCTS.new
1513

16-
run_benchmark(10) do
17-
mcts.start game_state, ITERATIONS
14+
if ENV["YJIT_BENCH_RACTOR_HARNESS"]
15+
run_benchmark(10) do
16+
state = Rubykon::GameState.new Rubykon::Game.new(19)
17+
m = MCTS::MCTS.new
18+
m.start state, ITERATIONS
19+
end
20+
else
21+
game_state = Rubykon::GameState.new Rubykon::Game.new(19)
22+
mcts = MCTS::MCTS.new
23+
run_benchmark(10) do
24+
mcts.start game_state, ITERATIONS
25+
end
1826
end

0 commit comments

Comments
 (0)