|
| 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 | +} |
0 commit comments