Skip to content

Commit 659f981

Browse files
committed
**Motivation:**
Remove old benchmark infra which causes sendability warnings. There's proper benchmark packages now and we should use them instead, depend on: https://github.com/ordo-one/package-benchmark.git **Modifications:** Remove custom benchmark infra. Adopt existing benchmark package -- this can also nicely track allocations. **Result:** No sendability warnings; less deprecated benchmark infra
1 parent 61c272f commit 659f981

File tree

10 files changed

+214
-1273
lines changed

10 files changed

+214
-1273
lines changed

Benchmarks/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.build/

Benchmarks/.gitkeep

Whitespace-only changes.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift Distributed Tracing open source project
4+
//
5+
// Copyright (c) 2020-2023 Apple Inc. and the Swift Distributed Tracing project
6+
// authors
7+
// Licensed under Apache License v2.0
8+
//
9+
// See LICENSE.txt for license information
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
import Benchmark
16+
import Tracing
17+
18+
let benchmarks = {
19+
let defaultMetrics: [BenchmarkMetric] = [
20+
.mallocCountTotal,
21+
]
22+
23+
Benchmark(
24+
"NoopTracing.startSpan/endSpan",
25+
configuration: .init(
26+
metrics: defaultMetrics,
27+
timeUnits: .nanoseconds,
28+
scalingFactor: .mega
29+
)
30+
) { benchmark in
31+
let span = startSpan("name")
32+
defer { span.end() }
33+
}
34+
35+
Benchmark(
36+
"NoopTracing.attribute: set, span.attributes['http.status_code'] = 200",
37+
configuration: .init(
38+
metrics: defaultMetrics,
39+
timeUnits: .nanoseconds,
40+
scalingFactor: .mega
41+
)
42+
) { benchmark in
43+
let span = startSpan("name")
44+
span.attributes["http.status_code"] = 200
45+
defer { span.end() }
46+
}
47+
48+
Benchmark(
49+
"NoopTracing.attribute: set, span.attributes.http.status_code = 200",
50+
configuration: .init(
51+
metrics: defaultMetrics,
52+
timeUnits: .nanoseconds,
53+
scalingFactor: .mega
54+
)
55+
) { benchmark in
56+
let span = startSpan("name")
57+
span.attributes.http.statusCode = 200
58+
defer { span.end() }
59+
}
60+
}
61+
62+
@dynamicMemberLookup
63+
struct HTTPAttributes: SpanAttributeNamespace {
64+
var attributes: SpanAttributes
65+
66+
init(attributes: SpanAttributes) {
67+
self.attributes = attributes
68+
}
69+
70+
struct NestedSpanAttributes: NestedSpanAttributesProtocol {
71+
init() {}
72+
73+
var method: Key<String> { "http.method" }
74+
var statusCode: Key<Int> { "http.status_code" }
75+
}
76+
}
77+
78+
extension SpanAttributes {
79+
var http: HTTPAttributes {
80+
get {
81+
.init(attributes: self)
82+
}
83+
set {
84+
self = newValue.attributes
85+
}
86+
}
87+
}

Benchmarks/Package.resolved

Lines changed: 86 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Benchmarks/Package.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// swift-tools-version: 5.9
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// This source file is part of the SwiftCertificates open source project
5+
//
6+
// Copyright (c) 2023 Apple Inc. and the SwiftCertificates project authors
7+
// Licensed under Apache License v2.0
8+
//
9+
// See LICENSE.txt for license information
10+
// See CONTRIBUTORS.txt for the list of SwiftCertificates project authors
11+
//
12+
// SPDX-License-Identifier: Apache-2.0
13+
//
14+
//===----------------------------------------------------------------------===//
15+
16+
import PackageDescription
17+
18+
let package = Package(
19+
name: "benchmarks",
20+
platforms: [
21+
.macOS("14"),
22+
],
23+
dependencies: [
24+
.package(path: "../"),
25+
.package(url: "https://github.com/ordo-one/package-benchmark.git", from: "1.22.0"),
26+
],
27+
targets: [
28+
.executableTarget(
29+
name: "TracingBenchmarks",
30+
dependencies: [
31+
.product(name: "Benchmark", package: "package-benchmark"),
32+
.product(name: "Tracing", package: "swift-distributed-tracing"),
33+
],
34+
path: "Benchmarks/TracingBenchmarks",
35+
plugins: [
36+
.plugin(name: "BenchmarkPlugin", package: "package-benchmark")
37+
]
38+
),
39+
]
40+
)

0 commit comments

Comments
 (0)