From 7e6decfd6b15828d5f0ec5088290972b5e7986f9 Mon Sep 17 00:00:00 2001 From: Si Beaumont Date: Wed, 2 Oct 2024 13:51:32 +0100 Subject: [PATCH] benchmarks: Add subdirectory Benchmarks/ package --- .gitignore | 2 +- .licenseignore | 2 +- .swiftformatignore | 2 +- .../OpenAPIRuntimeBenchmarks/Benchmarks.swift | 61 +++++++++++++++++++ Benchmarks/Package.swift | 24 ++++++++ 5 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 Benchmarks/Benchmarks/OpenAPIRuntimeBenchmarks/Benchmarks.swift create mode 100644 Benchmarks/Package.swift diff --git a/.gitignore b/.gitignore index c01c56a8..c4deea75 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ xcuserdata/ DerivedData/ .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata .vscode -/Package.resolved +Package.resolved .ci/ .docc-build/ .swiftpm diff --git a/.licenseignore b/.licenseignore index c0e92649..3767d5e3 100644 --- a/.licenseignore +++ b/.licenseignore @@ -6,5 +6,5 @@ .github/ **.md **.txt -Package.swift +**Package.swift docker/* diff --git a/.swiftformatignore b/.swiftformatignore index 4308420a..ef0b696a 100644 --- a/.swiftformatignore +++ b/.swiftformatignore @@ -1 +1 @@ -Package.swift +**Package.swift diff --git a/Benchmarks/Benchmarks/OpenAPIRuntimeBenchmarks/Benchmarks.swift b/Benchmarks/Benchmarks/OpenAPIRuntimeBenchmarks/Benchmarks.swift new file mode 100644 index 00000000..634a0d65 --- /dev/null +++ b/Benchmarks/Benchmarks/OpenAPIRuntimeBenchmarks/Benchmarks.swift @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the SwiftOpenAPIGenerator open source project +// +// Copyright (c) 2024 Apple Inc. and the SwiftOpenAPIGenerator project authors +// Licensed under Apache License v2.0 +// +// See LICENSE.txt for license information +// See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors +// +// SPDX-License-Identifier: Apache-2.0 +// +//===----------------------------------------------------------------------===// +import Benchmark +import OpenAPIRuntime +import Foundation + +let benchmarks = { + let defaultMetrics: [BenchmarkMetric] = [.mallocCountTotal, .cpuTotal] + + Benchmark( + "ISO8601DateTranscoder.encode(_:)", + configuration: Benchmark.Configuration( + metrics: defaultMetrics, + scalingFactor: .kilo, + maxDuration: .seconds(10_000_000), + maxIterations: 5 + ) + ) { benchmark in + let transcoder = ISO8601DateTranscoder() + benchmark.startMeasurement() + for _ in benchmark.scaledIterations { blackHole(try transcoder.encode(.distantFuture)) } + } + + Benchmark( + "ISO8601DateFormatter.string(from:)", + configuration: Benchmark.Configuration( + metrics: defaultMetrics, + scalingFactor: .kilo, + maxDuration: .seconds(10_000_000), + maxIterations: 5 + ) + ) { benchmark in + let formatter = ISO8601DateFormatter() + benchmark.startMeasurement() + for _ in benchmark.scaledIterations { blackHole(formatter.string(from: .distantFuture)) } + } + + Benchmark( + "Date.ISO8601Format(_:)", + configuration: Benchmark.Configuration( + metrics: defaultMetrics, + scalingFactor: .kilo, + maxDuration: .seconds(10_000_000), + maxIterations: 5 + ) + ) { benchmark in + benchmark.startMeasurement() + for _ in benchmark.scaledIterations { blackHole(Date.distantFuture.ISO8601Format()) } + } +} diff --git a/Benchmarks/Package.swift b/Benchmarks/Package.swift new file mode 100644 index 00000000..1294475e --- /dev/null +++ b/Benchmarks/Package.swift @@ -0,0 +1,24 @@ +// swift-tools-version: 5.9 +import PackageDescription + +let package = Package( + name: "swift-openapi-runtime-benchmarks", + platforms: [ .macOS("14") ], + dependencies: [ + .package(name: "swift-openapi-runtime", path: "../"), + .package(url: "https://github.com/ordo-one/package-benchmark.git", from: "1.22.0"), + ], + targets: [ + .executableTarget( + name: "OpenAPIRuntimeBenchmarks", + dependencies: [ + .product(name: "Benchmark", package: "package-benchmark"), + .product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"), + ], + path: "Benchmarks/OpenAPIRuntimeBenchmarks", + plugins: [ + .plugin(name: "BenchmarkPlugin", package: "package-benchmark") + ] + ), + ] +)