Skip to content

Commit

Permalink
gem loading benchmark needs to have the in-fork require fixed also
Browse files Browse the repository at this point in the history
  • Loading branch information
p committed Aug 7, 2024
1 parent fb70648 commit b37f157
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
27 changes: 1 addition & 26 deletions benchmarks/benchmarks_helper.rb
Original file line number Diff line number Diff line change
@@ -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'
26 changes: 26 additions & 0 deletions benchmarks/benchmarks_ips_patch.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion benchmarks/library_gem_loading.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b37f157

Please sign in to comment.