1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/benchmark/lib/benchmark_driver/runner/mjit.rb
2021-12-13 23:07:46 -08:00

34 lines
1.1 KiB
Ruby

require 'benchmark_driver/struct'
require 'benchmark_driver/metric'
require 'erb'
# A runner to measure after-JIT performance easily
class BenchmarkDriver::Runner::Mjit < BenchmarkDriver::Runner::Ips
# JobParser returns this, `BenchmarkDriver::Runner.runner_for` searches "*::Job"
Job = Class.new(BenchmarkDriver::DefaultJob)
# Dynamically fetched and used by `BenchmarkDriver::JobParser.parse`
JobParser = BenchmarkDriver::DefaultJobParser.for(klass: Job, metrics: [METRIC]).extend(Module.new{
def parse(**)
jobs = super
jobs.map do |job|
job = job.dup
job.prelude = "#{job.prelude}\n#{<<~EOS}"
if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
__bmdv_ruby_i = 0
while __bmdv_ruby_i < 10000 # jit_min_calls
#{job.script}
__bmdv_ruby_i += 1
end
RubyVM::MJIT.pause # compile
#{job.script}
RubyVM::MJIT.resume; RubyVM::MJIT.pause # recompile
#{job.script}
RubyVM::MJIT.resume; RubyVM::MJIT.pause # recompile 2
end
EOS
job
end
end
})
end