Skip to content

Commit

Permalink
Add benchmark for gem loading
Browse files Browse the repository at this point in the history
  • Loading branch information
marcotc committed Feb 24, 2024
1 parent d3b67fc commit 1496333
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions benchmarks/tracing_trace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
return unless __FILE__ == $PROGRAM_NAME || VALIDATE_BENCHMARK_MODE

require 'benchmark/ips'
require 'open3'

require 'ddtrace'

class TracingTraceBenchmark
Expand Down Expand Up @@ -163,6 +165,36 @@ def benchmark_propagation_trace_context
end
end
end

def benchmark_gem_loading
# This benchmark needs to be run in a clean environment where ddtrace is not loaded yet
output, status = Open3.capture2e('ruby', stdin_data: <<-RUBY)
raise "Datadog is already loaded" if defined?(::Datadog)
VALIDATE_BENCHMARK_MODE = ENV['VALIDATE_BENCHMARK'] == 'true'
require 'benchmark/ips'
Benchmark.ips do |x|
# Gem loading is quite slower than the other microbenchmarks
benchmark_time = VALIDATE_BENCHMARK_MODE ? { time: 0.001, warmup: 0 } : { time: 60, warmup: 5 }
x.config(**benchmark_time)
x.report("Gem loading") do
pid = fork { require 'ddtrace' }
_, status = Process.wait2(pid)
raise unless status.success?
end
x.save! "#{__FILE__}-results.json" unless VALIDATE_BENCHMARK_MODE
x.compare!
end
RUBY

print output

raise "Benchmark failed with status #{status}: #{output}" unless status.success?
end
end

puts "Current pid is #{Process.pid}"
Expand All @@ -183,4 +215,5 @@ def run_benchmark(&block)
run_benchmark { benchmark_to_digest_continue }
run_benchmark { benchmark_propagation_datadog }
run_benchmark { benchmark_propagation_trace_context }
run_benchmark { benchmark_gem_loading }
end

0 comments on commit 1496333

Please sign in to comment.