Skip to content

Commit 7e6decf

Browse files
benchmarks: Add subdirectory Benchmarks/ package
1 parent f795237 commit 7e6decf

File tree

5 files changed

+88
-3
lines changed

5 files changed

+88
-3
lines changed

Diff for: .gitignore

+1-1
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

Diff for: .licenseignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
.github/
77
**.md
88
**.txt
9-
Package.swift
9+
**Package.swift
1010
docker/*

Diff for: .swiftformatignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Package.swift
1+
**Package.swift
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the SwiftOpenAPIGenerator open source project
4+
//
5+
// Copyright (c) 2024 Apple Inc. and the SwiftOpenAPIGenerator 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 SwiftOpenAPIGenerator 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] = [.mallocCountTotal, .cpuTotal]
20+
21+
Benchmark(
22+
"ISO8601DateTranscoder.encode(_:)",
23+
configuration: Benchmark.Configuration(
24+
metrics: defaultMetrics,
25+
scalingFactor: .kilo,
26+
maxDuration: .seconds(10_000_000),
27+
maxIterations: 5
28+
)
29+
) { benchmark in
30+
let transcoder = ISO8601DateTranscoder()
31+
benchmark.startMeasurement()
32+
for _ in benchmark.scaledIterations { blackHole(try transcoder.encode(.distantFuture)) }
33+
}
34+
35+
Benchmark(
36+
"ISO8601DateFormatter.string(from:)",
37+
configuration: Benchmark.Configuration(
38+
metrics: defaultMetrics,
39+
scalingFactor: .kilo,
40+
maxDuration: .seconds(10_000_000),
41+
maxIterations: 5
42+
)
43+
) { benchmark in
44+
let formatter = ISO8601DateFormatter()
45+
benchmark.startMeasurement()
46+
for _ in benchmark.scaledIterations { blackHole(formatter.string(from: .distantFuture)) }
47+
}
48+
49+
Benchmark(
50+
"Date.ISO8601Format(_:)",
51+
configuration: Benchmark.Configuration(
52+
metrics: defaultMetrics,
53+
scalingFactor: .kilo,
54+
maxDuration: .seconds(10_000_000),
55+
maxIterations: 5
56+
)
57+
) { benchmark in
58+
benchmark.startMeasurement()
59+
for _ in benchmark.scaledIterations { blackHole(Date.distantFuture.ISO8601Format()) }
60+
}
61+
}

Diff for: Benchmarks/Package.swift

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