7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/bench.rb', line 7
def run(count: 3, frames: 1500, rom_path: 'lib/roms/tobu.gb')
time_sum = 0
count.times do |i|
emulator = Rubyboy::EmulatorHeadless.new(rom_path)
frame_count = 0
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond)
while frame_count < frames
emulator.step
frame_count += 1
end
time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond) - start_time
puts "#{i + 1}: #{time / 1_000_000_000.0} sec"
time_sum += time
end
puts "FPS: #{frames * count * 1_000_000_000.0 / time_sum}"
end
|