Skip to content

Commit 74ac22c

Browse files
committed
Remove old benchmark infra and replace with package-benchmark
**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 74ac22c

File tree

10 files changed

+214
-1273
lines changed

10 files changed

+214
-1273
lines changed

Benchmarks/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.build/

Benchmarks/.gitkeep

Whitespace-only changes.
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

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"pins" : [
3+
{
4+
"identity" : "hdrhistogram-swift",
5+
"kind" : "remoteSourceControl",
6+
"location" : "https://github.com/HdrHistogram/hdrhistogram-swift",
7+
"state" : {
8+
"revision" : "a69fa24d7b70421870cafa86340ece900489e17e",
9+
"version" : "0.1.2"
10+
}
11+
},
12+
{
13+
"identity" : "package-benchmark",
14+
"kind" : "remoteSourceControl",
15+
"location" : "https://github.com/ordo-one/package-benchmark.git",
16+
"state" : {
17+
"revision" : "ddf6c1ae01e139120bcdb917ece52819ee69d47a",
18+
"version" : "1.22.1"
19+
}
20+
},
21+
{
22+
"identity" : "package-jemalloc",
23+
"kind" : "remoteSourceControl",
24+
"location" : "https://github.com/ordo-one/package-jemalloc",
25+
"state" : {
26+
"revision" : "e8a5db026963f5bfeac842d9d3f2cc8cde323b49",
27+
"version" : "1.0.0"
28+
}
29+
},
30+
{
31+
"identity" : "swift-argument-parser",
32+
"kind" : "remoteSourceControl",
33+
"location" : "https://github.com/apple/swift-argument-parser",
34+
"state" : {
35+
"revision" : "c8ed701b513cf5177118a175d85fbbbcd707ab41",
36+
"version" : "1.3.0"
37+
}
38+
},
39+
{
40+
"identity" : "swift-atomics",
41+
"kind" : "remoteSourceControl",
42+
"location" : "https://github.com/apple/swift-atomics",
43+
"state" : {
44+
"revision" : "cd142fd2f64be2100422d658e7411e39489da985",
45+
"version" : "1.2.0"
46+
}
47+
},
48+
{
49+
"identity" : "swift-numerics",
50+
"kind" : "remoteSourceControl",
51+
"location" : "https://github.com/apple/swift-numerics",
52+
"state" : {
53+
"revision" : "0a5bc04095a675662cf24757cc0640aa2204253b",
54+
"version" : "1.0.2"
55+
}
56+
},
57+
{
58+
"identity" : "swift-service-context",
59+
"kind" : "remoteSourceControl",
60+
"location" : "https://github.com/apple/swift-service-context.git",
61+
"state" : {
62+
"revision" : "ce0141c8f123132dbd02fd45fea448018762df1b",
63+
"version" : "1.0.0"
64+
}
65+
},
66+
{
67+
"identity" : "swift-system",
68+
"kind" : "remoteSourceControl",
69+
"location" : "https://github.com/apple/swift-system",
70+
"state" : {
71+
"revision" : "025bcb1165deab2e20d4eaba79967ce73013f496",
72+
"version" : "1.2.1"
73+
}
74+
},
75+
{
76+
"identity" : "texttable",
77+
"kind" : "remoteSourceControl",
78+
"location" : "https://github.com/ordo-one/TextTable",
79+
"state" : {
80+
"revision" : "a27a07300cf4ae322e0079ca0a475c5583dd575f",
81+
"version" : "0.0.2"
82+
}
83+
}
84+
],
85+
"version" : 2
86+
}

Benchmarks/Package.swift

+40
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)