Skip to content

Commit b5591c3

Browse files
Unify Optcarrot benchmarks again.
This commit removes the need to copy any Optcarrot files, by using an approach based on the optcarrot-bench-parallel-on-ractor script included in Optcarrot, to make all necessary state shareable when the benchmark is running under the Ractor harness. Co-Authored-By: Matt Valentine-House <[email protected]>
1 parent 776a139 commit b5591c3

File tree

3 files changed

+42
-57
lines changed

3 files changed

+42
-57
lines changed

benchmarks-ractor/optcarrot/benchmark.rb

Lines changed: 0 additions & 50 deletions
This file was deleted.

benchmarks.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ nqueens:
8585
ractor: true
8686
optcarrot:
8787
desc: optcarrot is a functional headless NES emulator, run on a specific game cartridge for a specific number of frames.
88+
ractor: true
8889
protoboeuf:
8990
desc: protoboeuf (pure-Ruby protobuf) message decoding
9091
ractor: true
@@ -209,5 +210,3 @@ ractor/json_parse_float:
209210
desc: test the performance of parsing multiple lists of json floats with ractors.
210211
ractor/json_parse_string:
211212
desc: test the performance of parsing multiple lists of strings with ractors.
212-
ractor/optcarrot:
213-
desc: The NES emulator optcarrot, refactored to run inside multiple ractors.

benchmarks/optcarrot/benchmark.rb

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,46 @@
11
require_relative '../../harness/loader'
22
require_relative "lib/optcarrot"
33

4-
rom_path = File.join(__dir__, "examples/Lan_Master.nes")
5-
nes = Optcarrot::NES.new(["--headless", rom_path])
6-
nes.reset
4+
if ENV["RUBY_BENCH_RACTOR_HARNESS"]
5+
# Based on bin/optcarrot-bench-parallel-on-ractor
6+
[
7+
Optcarrot::Config::DEFAULT_OPTIONS,
8+
Optcarrot::Config::OPTIONS,
9+
Optcarrot::Driver::DRIVER_DB,
10+
Optcarrot::Audio::PACK_FORMAT,
11+
Optcarrot::APU::Pulse::WAVE_FORM,
12+
Optcarrot::APU::Triangle::WAVE_FORM,
13+
Optcarrot::APU::FRAME_CLOCKS,
14+
Optcarrot::APU::OSCILLATOR_CLOCKS,
15+
Optcarrot::APU::LengthCounter::LUT,
16+
Optcarrot::APU::Noise::LUT,
17+
Optcarrot::APU::Noise::NEXT_BITS_1,
18+
Optcarrot::APU::Noise::NEXT_BITS_6,
19+
Optcarrot::APU::DMC::LUT,
20+
Optcarrot::PPU::DUMMY_FRAME,
21+
Optcarrot::PPU::BOOT_FRAME,
22+
Optcarrot::PPU::SP_PIXEL_POSITIONS,
23+
Optcarrot::PPU::TILE_LUT,
24+
Optcarrot::PPU::NMT_TABLE,
25+
Optcarrot::CPU::DISPATCH,
26+
Optcarrot::ROM::MAPPER_DB,
27+
].each { |const| Ractor.make_shareable(const) }
728

8-
run_benchmark(10) do
9-
200.times { nes.step }
29+
ROM_PATH = File.join(__dir__, "examples/Lan_Master.nes").freeze
30+
ENV["WARMUP_ITRS"] = "1"
31+
32+
run_benchmark(10) do
33+
nes = Optcarrot::NES.new(["-b", "--no-print-video-checksum", ROM_PATH])
34+
nes.reset
35+
36+
200.times { nes.step }
37+
end
38+
else
39+
rom_path = File.join(__dir__, "examples/Lan_Master.nes")
40+
nes = Optcarrot::NES.new(["--headless", rom_path])
41+
nes.reset
42+
43+
run_benchmark(10) do
44+
200.times { nes.step }
45+
end
1046
end

0 commit comments

Comments
 (0)