Skip to content

Commit c29be53

Browse files
committed
Modify managed string storage benchmarking
Rather than comparing intern with intern_all (less useful now that DataDog/libdatadog#844 is merged), let's keep this around as a more generic measurement of managed string storage performance.
1 parent 032e7a3 commit c29be53

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

benchmarks/profiler_string_storage_intern.rb

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
require_relative 'benchmarks_helper'
77

8-
# This benchmark measures the performance of string storage intern/intern_all APIs
8+
# This benchmark measures the performance of string storage-related APIs
99

1010
class ProfilerStringStorageIntern
1111
def initialize
@@ -18,16 +18,37 @@ def run_benchmark
1818
x.config(
1919
**benchmark_time,
2020
)
21-
22-
x.report('intern 1000 strings') do
23-
Datadog::Profiling::StackRecorder::Testing._native_benchmark_intern(@recorder, "hello, world!", 1000, false)
21+
x.report('intern_all 1000 repeated strings') do
22+
Datadog::Profiling::StackRecorder::Testing._native_benchmark_intern(@recorder, "hello, world!", 1000, true)
2423
end
2524

26-
x.report('intern_all 1000 strings') do
27-
Datadog::Profiling::StackRecorder::Testing._native_benchmark_intern(@recorder, "hello, world!", 1000, true)
25+
x.save! "#{File.basename(__FILE__)}-1-results.json" unless VALIDATE_BENCHMARK_MODE
26+
x.compare!
27+
end
28+
29+
Benchmark.ips do |x|
30+
benchmark_time = VALIDATE_BENCHMARK_MODE ? { time: 0.01, warmup: 0 } : { time: 10, warmup: 2 }
31+
x.config(
32+
**benchmark_time,
33+
)
34+
35+
x.report('intern mixed existing and new') do
36+
recorder = Datadog::Profiling::StackRecorder.for_testing(heap_samples_enabled: true)
37+
38+
strings_to_intern = 100_000
39+
existing_strings = (strings_to_intern * 0.9).to_i
40+
new_strings = strings_to_intern - existing_strings
41+
42+
new_strings.times do |i|
43+
Datadog::Profiling::StackRecorder::Testing._native_benchmark_intern(recorder, ("%010d" % i), 1, false)
44+
end
45+
46+
existing_strings.times do |i|
47+
Datadog::Profiling::StackRecorder::Testing._native_benchmark_intern(recorder, "hello, world!", 1, false)
48+
end
2849
end
2950

30-
x.save! "#{File.basename(__FILE__)}-results.json" unless VALIDATE_BENCHMARK_MODE
51+
x.save! "#{File.basename(__FILE__)}-2-results.json" unless VALIDATE_BENCHMARK_MODE
3152
x.compare!
3253
end
3354
end

0 commit comments

Comments
 (0)