Skip to content

Commit 2edf4cf

Browse files
authored
Add a benchmark for rubyboy's headless emulator (#359)
The repo is a gem so we can just use it from our Gemfile. The rom is included. The current loop produces results similar to our optcarrot benchmark. cruby: ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [arm64-darwin23] yjit: ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +YJIT +PRISM [arm64-darwin23] --------- ---------- ---------- --------- ---------- ------------ ---------- bench cruby (ms) stddev (%) yjit (ms) stddev (%) yjit 1st itr cruby/yjit optcarrot 3100.0 0.6 800.8 1.7 3.599 3.871 rubyboy 2764.1 0.5 991.9 1.0 2.606 2.787 --------- ---------- ---------- --------- ---------- ------------ ---------- Legend: - yjit 1st itr: ratio of cruby/yjit time for the first benchmarking iteration. - cruby/yjit: ratio of cruby/yjit time. Higher is better for yjit. Above 1 represents a speedup.
1 parent 35773de commit 2edf4cf

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed

benchmarks.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ rack:
7171
desc: test the performance of the Rack framework with barely any routing.
7272
ruby-json:
7373
desc: an optimized version of the json_pure gem's pure Ruby JSON parser.
74+
rubyboy:
75+
desc: Rubyboy is a functional headless GameBoy emulator, run on a specific game cartridge for a specific number of frames.
7476
rubykon:
7577
desc: Ruby solver for Go (the boardgame.) Runs many iterations forward from an initial starting board.
7678
tinygql:

benchmarks/rubyboy/Gemfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
4+
5+
gem "rubyboy", git: "https://github.com/sacckey/rubyboy"

benchmarks/rubyboy/Gemfile.lock

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
GIT
2+
remote: https://github.com/sacckey/rubyboy
3+
revision: e6c7d1d64ed7c6edb0ec6bae25ae3e7ec4cc9319
4+
specs:
5+
rubyboy (1.5.0)
6+
ffi (~> 1.16, >= 1.16.3)
7+
8+
GEM
9+
remote: https://rubygems.org/
10+
specs:
11+
ffi (1.17.1)
12+
ffi (1.17.1-aarch64-linux-gnu)
13+
ffi (1.17.1-aarch64-linux-musl)
14+
ffi (1.17.1-arm-linux-gnu)
15+
ffi (1.17.1-arm-linux-musl)
16+
ffi (1.17.1-arm64-darwin)
17+
ffi (1.17.1-x86-linux-gnu)
18+
ffi (1.17.1-x86-linux-musl)
19+
ffi (1.17.1-x86_64-darwin)
20+
ffi (1.17.1-x86_64-linux-gnu)
21+
ffi (1.17.1-x86_64-linux-musl)
22+
23+
PLATFORMS
24+
aarch64-linux-gnu
25+
aarch64-linux-musl
26+
arm-linux-gnu
27+
arm-linux-musl
28+
arm64-darwin
29+
ruby
30+
x86-linux-gnu
31+
x86-linux-musl
32+
x86_64-darwin
33+
x86_64-linux-gnu
34+
x86_64-linux-musl
35+
36+
DEPENDENCIES
37+
rubyboy!
38+
39+
BUNDLED WITH
40+
2.4.19

benchmarks/rubyboy/benchmark.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "../../harness/loader"
4+
5+
Dir.chdir(__dir__)
6+
use_gemfile
7+
8+
# Rubyboy has a Bench module which is just a loop around `emulator.step`.
9+
# https://github.com/sacckey/rubyboy/blob/e6c7d1d64ed7c6edb0ec6bae25ae3e7ec4cc9319/lib/bench.rb
10+
11+
require 'rubyboy/emulator_headless'
12+
13+
# 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") })
15+
16+
# A count of 500 produces results similar to our optcarrot benchmark.
17+
# It's possible there is a number that produces a consistent benchmark without
18+
# needing to re-initialize but not sure how to determine that.
19+
count = 500
20+
21+
run_benchmark(200) do
22+
# Results are much more consistent if we re-initialize each time.
23+
# Reusing the same eumlator increases stddev by 65x.
24+
emulator = Rubyboy::EmulatorHeadless.new(rom_path)
25+
count.times do
26+
emulator.step
27+
end
28+
end

0 commit comments

Comments
 (0)