5
5
6
6
require_relative 'benchmarks_helper'
7
7
8
- # This benchmark measures the performance of string storage intern/intern_all APIs
8
+ # This benchmark measures the performance of string storage-related APIs
9
9
10
10
class ProfilerStringStorageIntern
11
11
def initialize
@@ -18,16 +18,37 @@ def run_benchmark
18
18
x . config (
19
19
**benchmark_time ,
20
20
)
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 )
24
23
end
25
24
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
28
49
end
29
50
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
31
52
x . compare!
32
53
end
33
54
end
0 commit comments