Skip to content

Commit

Permalink
di
Browse files Browse the repository at this point in the history
  • Loading branch information
p committed Oct 1, 2024
1 parent 8f1a8a9 commit 7c51009
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions benchmarks/di_instrument.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
=begin
"Instrumentation" part of Dynamic Instrumentation benchmarks.
Typical result:
Comparison:
no instrumentation: 589490.0 i/s
method instrumentation - cleared: 545807.2 i/s - 1.08x slower
line instrumentation - cleared: 539686.5 i/s - 1.09x slower
no instrumentation - again: 535761.0 i/s - 1.10x slower
method instrumentation: 129159.5 i/s - 4.56x slower
line instrumentation - targeted: 128848.6 i/s - 4.58x slower
line instrumentation: 10771.7 i/s - 54.73x slower
In theory, after instrumentation is removed, performance should return to
the baseline. We are currently observing about a 6-10% performance loss.
Two theories for why this is so:
1. Some overhead remains in the code - to be investigated.
2. The benchmarks were run on a laptop, and during the benchmarking
process the CPU is heating up and it can't turbo to the same speeds at
the end of the run as it can at the beginning. Meaning the observed 6-10%
slowdown at the end is an environmental issue and not an implementation
problem.
=end

# Used to quickly run benchmark under RSpec as part of the usual test suite, to validate it didn't bitrot
VALIDATE_BENCHMARK_MODE = ENV['VALIDATE_BENCHMARK'] == 'true'

Expand All @@ -13,6 +40,10 @@ def test_method
SecureRandom.uuid
end

def not_instrumented
SecureRandom.uuid
end

# This method must have an executable line as its first line,
# otherwise line instrumentation won't work.
# The code in this method should be identical to test_method above.
Expand Down Expand Up @@ -192,6 +223,20 @@ def run_benchmark
raise "Line instrumentation was not cleared (#{calls} calls recorded)"
end

Benchmark.ips do |x|
benchmark_time = VALIDATE_BENCHMARK_MODE ? { time: 0.01, warmup: 0 } : { time: 10, warmup: 2 }
x.config(
**benchmark_time,
)

x.report('no instrumentation - again') do
Target.new.not_instrumented
end

x.save! 'di-instrument-results.json' unless VALIDATE_BENCHMARK_MODE
x.compare!
end

end

end
Expand Down

0 comments on commit 7c51009

Please sign in to comment.