ruby-changes:61889
From: Takashi <ko1@a...>
Date: Mon, 22 Jun 2020 16:55:11 +0900 (JST)
Subject: [ruby-changes:61889] 4c5780e51e (master): Share warmup logic across MJIT benchmarks
https://git.ruby-lang.org/ruby.git/commit/?id=4c5780e51e From 4c5780e51ef1cd122c6cff863657bd7c523d65ec Mon Sep 17 00:00:00 2001 From: Takashi Kokubun <takashikkbn@g...> Date: Mon, 22 Jun 2020 00:54:27 -0700 Subject: Share warmup logic across MJIT benchmarks diff --git a/benchmark/lib/benchmark_driver/runner/mjit.rb b/benchmark/lib/benchmark_driver/runner/mjit.rb new file mode 100644 index 0000000..1d4693e --- /dev/null +++ b/benchmark/lib/benchmark_driver/runner/mjit.rb @@ -0,0 +1,34 @@ https://github.com/ruby/ruby/blob/trunk/benchmark/lib/benchmark_driver/runner/mjit.rb#L1 +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 diff --git a/benchmark/mjit_exivar.yml b/benchmark/mjit_exivar.yml index e6fbae9..2584fa6 100644 --- a/benchmark/mjit_exivar.yml +++ b/benchmark/mjit_exivar.yml @@ -1,3 +1,4 @@ https://github.com/ruby/ruby/blob/trunk/benchmark/mjit_exivar.yml#L1 +type: lib/benchmark_driver/runner/mjit prelude: | class Bench < Hash def initialize @@ -11,20 +12,6 @@ prelude: | https://github.com/ruby/ruby/blob/trunk/benchmark/mjit_exivar.yml#L12 bench = Bench.new - if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? - jit_min_calls = 10000 - i = 0 - while i < jit_min_calls - bench.exivar - i += 1 - end - RubyVM::MJIT.pause # compile (1) - # issue recompile - bench.exivar - RubyVM::MJIT.resume - RubyVM::MJIT.pause # compile (2) - end - benchmark: mjit_exivar: bench.exivar diff --git a/benchmark/mjit_int_zero_p.yml b/benchmark/mjit_int_zero_p.yml index 91e8ea0..f8950ba 100644 --- a/benchmark/mjit_int_zero_p.yml +++ b/benchmark/mjit_int_zero_p.yml @@ -1,3 +1,4 @@ https://github.com/ruby/ruby/blob/trunk/benchmark/mjit_int_zero_p.yml#L1 +type: lib/benchmark_driver/runner/mjit prelude: | def mjit_zero?(int) int.zero? @@ -7,30 +8,14 @@ prelude: | https://github.com/ruby/ruby/blob/trunk/benchmark/mjit_int_zero_p.yml#L8 int == 0 end - def warmup(sym, int) - if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? - jit_min_calls = 10000 - i = 0 - while i < jit_min_calls - send(sym, int) - i += 1 - end - RubyVM::MJIT.pause - end - end - benchmark: - name: 0.zero? - prelude: warmup(:mjit_zero?, 0) script: mjit_zero?(0) - name: 1.zero? - prelude: warmup(:mjit_zero?, 1) script: mjit_zero?(1) - name: 0 == 0 - prelude: warmup(:mjit_eq_0, 0) script: mjit_eq_0(0) - name: 1 == 0 - prelude: warmup(:mjit_eq_0, 1) script: mjit_eq_0(1) loop_count: 40000000 diff --git a/benchmark/mjit_leave.yml b/benchmark/mjit_leave.yml index 292d6ef..9ac68b1 100644 --- a/benchmark/mjit_leave.yml +++ b/benchmark/mjit_leave.yml @@ -1,3 +1,4 @@ https://github.com/ruby/ruby/blob/trunk/benchmark/mjit_leave.yml#L1 +type: lib/benchmark_driver/runner/mjit prelude: | def leave nil diff --git a/benchmark/mjit_send_cfunc.yml b/benchmark/mjit_send_cfunc.yml index b5f9c89..8caa62c 100644 --- a/benchmark/mjit_send_cfunc.yml +++ b/benchmark/mjit_send_cfunc.yml @@ -1,3 +1,4 @@ https://github.com/ruby/ruby/blob/trunk/benchmark/mjit_send_cfunc.yml#L1 +type: lib/benchmark_driver/runner/mjit prelude: | def mjit_send_cfunc self.class -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/