From c75deec5a0917248f23d75898205a44ef785875c Mon Sep 17 00:00:00 2001 From: Randy Stauner Date: Thu, 12 Sep 2024 09:34:39 -0700 Subject: [PATCH] Check that the ruby configuration isn't changed during the benchmark --- harness/harness.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/harness/harness.rb b/harness/harness.rb index 9fa868d2..162c02d1 100644 --- a/harness/harness.rb +++ b/harness/harness.rb @@ -16,6 +16,13 @@ system('mkdir', '-p', File.dirname(OUT_CSV_PATH)) +# We could include other values in this result if more become relevant +# but for now all we want to know is if YJIT was enabled at runtime. +def yjit_enabled? + RubyVM::YJIT.enabled? if defined?(RubyVM::YJIT) +end +ORIGINAL_YJIT_ENABLED = yjit_enabled? + puts RUBY_DESCRIPTION def realtime @@ -52,4 +59,8 @@ def run_benchmark(_num_itrs_hint, &block) non_warmups_ms = ((non_warmups.sum / non_warmups.size) * 1000.0).to_i puts "Average of last #{non_warmups.size}, non-warmup iters: #{non_warmups_ms}ms" end + + if yjit_enabled? != ORIGINAL_YJIT_ENABLED + raise "Benchmark altered YJIT configuration! (changed from #{ORIGINAL_YJIT_ENABLED.inspect} to #{yjit_enabled?.inspect})" + end end