Skip to content

Commit 2e6b5ca

Browse files
benchmarks: Add subdirectory Benchmarks/ package
1 parent f795237 commit 2e6b5ca

File tree

3 files changed

+95
-1
lines changed

3 files changed

+95
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ xcuserdata/
66
DerivedData/
77
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
88
.vscode
9-
/Package.resolved
9+
Package.resolved
1010
.ci/
1111
.docc-build/
1212
.swiftpm
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the SwiftOpenAPIGenerator open source project
4+
//
5+
// Copyright (c) 2024 Apple Inc. and the SwiftNIO project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
import Benchmark
15+
import OpenAPIRuntime
16+
import Foundation
17+
18+
let benchmarks = {
19+
let defaultMetrics: [BenchmarkMetric] = [
20+
.mallocCountTotal,
21+
.cpuTotal,
22+
]
23+
24+
Benchmark(
25+
"ISO8601DateTranscoder.encode(_:)",
26+
configuration: Benchmark.Configuration(
27+
metrics: defaultMetrics,
28+
scalingFactor: .kilo,
29+
maxDuration: .seconds(10_000_000),
30+
maxIterations: 5
31+
)
32+
) { benchmark in
33+
let transcoder = ISO8601DateTranscoder()
34+
benchmark.startMeasurement()
35+
for _ in benchmark.scaledIterations {
36+
blackHole(try transcoder.encode(.distantFuture))
37+
}
38+
}
39+
40+
Benchmark(
41+
"ISO8601DateFormatter.string(from:)",
42+
configuration: Benchmark.Configuration(
43+
metrics: defaultMetrics,
44+
scalingFactor: .kilo,
45+
maxDuration: .seconds(10_000_000),
46+
maxIterations: 5
47+
)
48+
) { benchmark in
49+
let formatter = ISO8601DateFormatter()
50+
benchmark.startMeasurement()
51+
for _ in benchmark.scaledIterations {
52+
blackHole(formatter.string(from: .distantFuture))
53+
}
54+
}
55+
56+
Benchmark(
57+
"Date.ISO8601Format(_:)",
58+
configuration: Benchmark.Configuration(
59+
metrics: defaultMetrics,
60+
scalingFactor: .kilo,
61+
maxDuration: .seconds(10_000_000),
62+
maxIterations: 5
63+
)
64+
) { benchmark in
65+
benchmark.startMeasurement()
66+
for _ in benchmark.scaledIterations {
67+
blackHole(Date.distantFuture.ISO8601Format())
68+
}
69+
}
70+
}

Benchmarks/Package.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// swift-tools-version: 5.9
2+
import PackageDescription
3+
4+
let package = Package(
5+
name: "swift-openapi-runtime-benchmarks",
6+
platforms: [ .macOS("14") ],
7+
dependencies: [
8+
.package(name: "swift-openapi-runtime", path: "../"),
9+
.package(url: "https://github.com/ordo-one/package-benchmark.git", from: "1.22.0"),
10+
],
11+
targets: [
12+
.executableTarget(
13+
name: "OpenAPIRuntimeBenchmarks",
14+
dependencies: [
15+
.product(name: "Benchmark", package: "package-benchmark"),
16+
.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
17+
],
18+
path: "Benchmarks/OpenAPIRuntimeBenchmarks",
19+
plugins: [
20+
.plugin(name: "BenchmarkPlugin", package: "package-benchmark")
21+
]
22+
),
23+
]
24+
)

0 commit comments

Comments
 (0)