From b37f15791830874c4a5107562609af9fc67645c6 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 7 Aug 2024 10:32:38 -0400 Subject: [PATCH] gem loading benchmark needs to have the in-fork require fixed also --- benchmarks/benchmarks_helper.rb | 27 +-------------------------- benchmarks/benchmarks_ips_patch.rb | 26 ++++++++++++++++++++++++++ benchmarks/library_gem_loading.rb | 3 ++- 3 files changed, 29 insertions(+), 27 deletions(-) create mode 100644 benchmarks/benchmarks_ips_patch.rb diff --git a/benchmarks/benchmarks_helper.rb b/benchmarks/benchmarks_helper.rb index bf7162ed34..5368594c6f 100644 --- a/benchmarks/benchmarks_helper.rb +++ b/benchmarks/benchmarks_helper.rb @@ -1,28 +1,3 @@ -require 'benchmark/ips' require 'datadog' require 'pry' - -module JobReporter - def report(name, *args, **opts, &block) - caller_path = caller_locations.first.path - prefix = File.basename(caller_path).sub(/_.*\z/, '') - name = "#{prefix} - #{name}" - # Older Rubies (e.g. 2.5) do not permit passing *args and &block - # in the same invocation. - if args.any? && block_given? - raise ArgumentError, 'Unsupported usage' - elsif block_given? - if opts.any? - super(name, **opts, &block) - else - super(name, &block) - end - else - super(name, *args, **opts) - end - end -end - -class Benchmark::IPS::Job - prepend JobReporter -end +require_relative 'benchmarks_ips_patch' diff --git a/benchmarks/benchmarks_ips_patch.rb b/benchmarks/benchmarks_ips_patch.rb new file mode 100644 index 0000000000..a7ec63af74 --- /dev/null +++ b/benchmarks/benchmarks_ips_patch.rb @@ -0,0 +1,26 @@ +require 'benchmark/ips' + +module JobReporter + def report(name, *args, **opts, &block) + caller_path = caller_locations.first.path + prefix = File.basename(caller_path).sub(/_.*\z/, '') + name = "#{prefix} - #{name}" + # Older Rubies (e.g. 2.5) do not permit passing *args and &block + # in the same invocation. + if args.any? && block_given? + raise ArgumentError, 'Unsupported usage' + elsif block_given? + if opts.any? + super(name, **opts, &block) + else + super(name, &block) + end + else + super(name, *args, **opts) + end + end +end + +class Benchmark::IPS::Job + prepend JobReporter +end diff --git a/benchmarks/library_gem_loading.rb b/benchmarks/library_gem_loading.rb index 428ccf34a4..d5dac4fc37 100644 --- a/benchmarks/library_gem_loading.rb +++ b/benchmarks/library_gem_loading.rb @@ -19,9 +19,10 @@ def benchmark_gem_loading lib = File.expand_path('../lib', '#{__dir__}') $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) + $LOAD_PATH.unshift('#{__dir__}') VALIDATE_BENCHMARK_MODE = #{VALIDATE_BENCHMARK_MODE} - require 'benchmark/ips' + require 'benchmarks_ips_patch' Benchmark.ips do |x| # Gem loading is quite slower than the other microbenchmarks