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
Takashi Kokubun e1fee7f949
Rename RubyVM::MJIT to RubyVM::JIT
because the name "MJIT" is an internal code name, it's inconsistent with
--jit while they are related to each other, and I want to discourage future
JIT implementation-specific (e.g. MJIT-specific) APIs by this rename.

[Feature #17490]
2021-01-13 22:46:51 -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::JIT) && RubyVM::JIT.enabled?
__bmdv_ruby_i = 0
while __bmdv_ruby_i < 10000 # jit_min_calls
#{job.script}
__bmdv_ruby_i += 1
end
RubyVM::JIT.pause # compile
#{job.script}
RubyVM::JIT.resume; RubyVM::JIT.pause # recompile
#{job.script}
RubyVM::JIT.resume; RubyVM::JIT.pause # recompile 2
end
EOS
job
end
end
})
end