15
15
import _TracingBenchmarkTools
16
16
import Tracing
17
17
18
- public let SpanAttributesDSLBenchmarks : [ BenchmarkInfo ] = [
19
- BenchmarkInfo (
20
- name: " SpanAttributesDSLBenchmarks.000_bench_empty " ,
21
- runFunction: { _ in try ! bench_empty ( times: 100 ) } ,
22
- tags: [ ] ,
23
- setUpFunction: { setUp ( ) } ,
24
- tearDownFunction: tearDown
25
- ) ,
26
- BenchmarkInfo (
27
- name: " SpanAttributesDSLBenchmarks.001_bench_makeSpan " ,
28
- runFunction: { _ in try ! bench_makeSpan ( times: 100 ) } ,
29
- tags: [ ] ,
30
- setUpFunction: { setUp ( ) } ,
31
- tearDownFunction: tearDown
32
- ) ,
33
- BenchmarkInfo (
34
- name: " SpanAttributesDSLBenchmarks.002_bench_startSpan_end " ,
35
- runFunction: { _ in try ! bench_makeSpan ( times: 100 ) } ,
36
- tags: [ ] ,
37
- setUpFunction: { setUp ( ) } ,
38
- tearDownFunction: tearDown
39
- ) ,
40
-
41
- BenchmarkInfo (
42
- name: " SpanAttributesDSLBenchmarks.00_bench_set_String_raw " ,
43
- runFunction: { _ in try ! bench_set_String_raw ( times: 100 ) } ,
44
- tags: [ ] ,
45
- setUpFunction: { setUp ( ) } ,
46
- tearDownFunction: tearDown
47
- ) ,
48
- BenchmarkInfo (
49
- name: " SpanAttributesDSLBenchmarks.01_bench_set_String_dsl " ,
50
- runFunction: { _ in try ! bench_set_String_dsl ( times: 100 ) } ,
51
- tags: [ ] ,
52
- setUpFunction: { setUp ( ) } ,
53
- tearDownFunction: tearDown
54
- ) ,
55
-
56
- BenchmarkInfo (
57
- name: " SpanAttributesDSLBenchmarks.02_bench_set_Int_raw " ,
58
- runFunction: { _ in try ! bench_set_String_raw ( times: 100 ) } ,
59
- tags: [ ] ,
60
- setUpFunction: { setUp ( ) } ,
61
- tearDownFunction: tearDown
62
- ) ,
63
- BenchmarkInfo (
64
- name: " SpanAttributesDSLBenchmarks.03_bench_set_Int_dsl " ,
65
- runFunction: { _ in try ! bench_set_String_dsl ( times: 100 ) } ,
66
- tags: [ ] ,
67
- setUpFunction: { setUp ( ) } ,
68
- tearDownFunction: tearDown
69
- ) ,
70
- ]
71
-
72
- private var span : ( any Tracing . Span ) !
73
-
74
- private func setUp( ) {
75
- span = InstrumentationSystem . legacyTracer. startAnySpan ( " something " , context: . topLevel)
76
- }
18
+ @available ( macOS 10 . 15 , iOS 13 , tvOS 13 , watchOS 6 , * ) // for TaskLocal ServiceContext
19
+ enum DSLBenchmarks {
20
+ public static let SpanAttributesDSLBenchmarks : [ BenchmarkInfo ] = [
21
+ BenchmarkInfo (
22
+ name: " SpanAttributesDSLBenchmarks.000_bench_empty " ,
23
+ runFunction: { _ in try ! bench_empty ( times: 100 ) } ,
24
+ tags: [ ] ,
25
+ setUpFunction: { setUp ( ) } ,
26
+ tearDownFunction: tearDown
27
+ ) ,
28
+ BenchmarkInfo (
29
+ name: " SpanAttributesDSLBenchmarks.001_bench_makeSpan " ,
30
+ runFunction: { _ in try ! bench_makeSpan ( times: 100 ) } ,
31
+ tags: [ ] ,
32
+ setUpFunction: { setUp ( ) } ,
33
+ tearDownFunction: tearDown
34
+ ) ,
35
+ BenchmarkInfo (
36
+ name: " SpanAttributesDSLBenchmarks.002_bench_startSpan_end " ,
37
+ runFunction: { _ in try ! bench_makeSpan ( times: 100 ) } ,
38
+ tags: [ ] ,
39
+ setUpFunction: { setUp ( ) } ,
40
+ tearDownFunction: tearDown
41
+ ) ,
42
+
43
+ BenchmarkInfo (
44
+ name: " SpanAttributesDSLBenchmarks.00_bench_set_String_raw " ,
45
+ runFunction: { _ in try ! bench_set_String_raw ( times: 100 ) } ,
46
+ tags: [ ] ,
47
+ setUpFunction: { setUp ( ) } ,
48
+ tearDownFunction: tearDown
49
+ ) ,
50
+ BenchmarkInfo (
51
+ name: " SpanAttributesDSLBenchmarks.01_bench_set_String_dsl " ,
52
+ runFunction: { _ in try ! bench_set_String_dsl ( times: 100 ) } ,
53
+ tags: [ ] ,
54
+ setUpFunction: { setUp ( ) } ,
55
+ tearDownFunction: tearDown
56
+ ) ,
57
+
58
+ BenchmarkInfo (
59
+ name: " SpanAttributesDSLBenchmarks.02_bench_set_Int_raw " ,
60
+ runFunction: { _ in try ! bench_set_String_raw ( times: 100 ) } ,
61
+ tags: [ ] ,
62
+ setUpFunction: { setUp ( ) } ,
63
+ tearDownFunction: tearDown
64
+ ) ,
65
+ BenchmarkInfo (
66
+ name: " SpanAttributesDSLBenchmarks.03_bench_set_Int_dsl " ,
67
+ runFunction: { _ in try ! bench_set_String_dsl ( times: 100 ) } ,
68
+ tags: [ ] ,
69
+ setUpFunction: { setUp ( ) } ,
70
+ tearDownFunction: tearDown
71
+ ) ,
72
+ ]
73
+
74
+ fileprivate static var span : ( any Tracing . Span ) !
75
+
76
+ fileprivate static func setUp( ) {
77
+ self . span = InstrumentationSystem . legacyTracer. startAnySpan ( " something " , context: . topLevel)
78
+ }
77
79
78
- private func tearDown( ) {
79
- span = nil
80
- }
80
+ fileprivate static func tearDown( ) {
81
+ self . span = nil
82
+ }
81
83
82
- // ==== ----------------------------------------------------------------------------------------------------------------
83
- // MARK: make span
84
+ // ==== ----------------------------------------------------------------------------------------------------------------
85
+ // MARK: make span
84
86
85
- func bench_empty( times: Int ) throws { }
87
+ static func bench_empty( times: Int ) throws { }
86
88
87
- func bench_makeSpan( times: Int ) throws {
88
- for _ in 0 ..< times {
89
- let span = InstrumentationSystem . legacyTracer. startAnySpan ( " something " , context: . topLevel)
90
- _ = span
89
+ static func bench_makeSpan( times: Int ) throws {
90
+ for _ in 0 ..< times {
91
+ let span = InstrumentationSystem . legacyTracer. startAnySpan ( " something " , context: . topLevel)
92
+ _ = span
93
+ }
91
94
}
92
- }
93
95
94
- func bench_startSpan_end( times: Int ) throws {
95
- for _ in 0 ..< times {
96
- let span = InstrumentationSystem . legacyTracer. startAnySpan ( " something " , context: . topLevel)
97
- span. end ( )
96
+ static func bench_startSpan_end( times: Int ) throws {
97
+ for _ in 0 ..< times {
98
+ let span = InstrumentationSystem . legacyTracer. startAnySpan ( " something " , context: . topLevel)
99
+ span. end ( )
100
+ }
98
101
}
99
- }
100
102
101
- // ==== ----------------------------------------------------------------------------------------------------------------
102
- // MARK: set String
103
+ // ==== ----------------------------------------------------------------------------------------------------------------
104
+ // MARK: set String
103
105
104
- func bench_set_String_raw( times: Int ) throws {
105
- for _ in 0 ..< times {
106
- span. attributes [ " http.method " ] = " POST "
106
+ static func bench_set_String_raw( times: Int ) throws {
107
+ for _ in 0 ..< times {
108
+ self . span. attributes [ " http.method " ] = " POST "
109
+ }
107
110
}
108
- }
109
111
110
- func bench_set_String_dsl( times: Int ) throws {
111
- for _ in 0 ..< times {
112
- span. attributes. http. method = " POST "
112
+ static func bench_set_String_dsl( times: Int ) throws {
113
+ for _ in 0 ..< times {
114
+ self . span. attributes. http. method = " POST "
115
+ }
113
116
}
114
- }
115
117
116
- // ==== ----------------------------------------------------------------------------------------------------------------
117
- // MARK: set Int
118
+ // ==== ----------------------------------------------------------------------------------------------------------------
119
+ // MARK: set Int
118
120
119
- func bench_set_Int_raw( times: Int ) throws {
120
- for _ in 0 ..< times {
121
- span. attributes [ " http.status_code " ] = 200
121
+ static func bench_set_Int_raw( times: Int ) throws {
122
+ for _ in 0 ..< times {
123
+ self . span. attributes [ " http.status_code " ] = 200
124
+ }
122
125
}
123
- }
124
126
125
- func bench_set_Int_dsl( times: Int ) throws {
126
- for _ in 0 ..< times {
127
- span. attributes. http. statusCode = 200
127
+ static func bench_set_Int_dsl( times: Int ) throws {
128
+ for _ in 0 ..< times {
129
+ self . span. attributes. http. statusCode = 200
130
+ }
131
+ }
132
+
133
+ @dynamicMemberLookup
134
+ struct HTTPAttributes : SpanAttributeNamespace {
135
+ var attributes : SpanAttributes
136
+
137
+ init ( attributes: SpanAttributes ) {
138
+ self . attributes = attributes
139
+ }
140
+
141
+ struct NestedSpanAttributes : NestedSpanAttributesProtocol {
142
+ init ( ) { }
143
+
144
+ var method : Key < String > { " http.method " }
145
+ var statusCode : Key < Int > { " http.status_code " }
146
+ }
128
147
}
129
148
}
130
149
150
+ @available ( macOS 10 . 15 , iOS 13 , tvOS 13 , watchOS 6 , * ) // for TaskLocal ServiceContext
131
151
extension SpanAttributes {
132
- var http : HTTPAttributes {
152
+ var http : DSLBenchmarks . HTTPAttributes {
133
153
get {
134
154
. init( attributes: self )
135
155
}
@@ -138,19 +158,3 @@ extension SpanAttributes {
138
158
}
139
159
}
140
160
}
141
-
142
- @dynamicMemberLookup
143
- struct HTTPAttributes : SpanAttributeNamespace {
144
- var attributes : SpanAttributes
145
-
146
- init ( attributes: SpanAttributes ) {
147
- self . attributes = attributes
148
- }
149
-
150
- struct NestedSpanAttributes : NestedSpanAttributesProtocol {
151
- init ( ) { }
152
-
153
- var method : Key < String > { " http.method " }
154
- var statusCode : Key < Int > { " http.status_code " }
155
- }
156
- }
0 commit comments