From e6905bfcef7bf97f653ed91d3e08478eac65d9d8 Mon Sep 17 00:00:00 2001 From: David Nadoba Date: Tue, 22 Aug 2023 08:55:21 +0100 Subject: [PATCH] Apply review feedback --- .../CertificatesBenchmarks/Benchmarks.swift | 7 ++++- benchmarks/Package.swift | 1 + benchmarks/Sources/ParseWebPKI.swift | 1 + benchmarks/Sources/TinyArrayAppend.swift | 1 + .../TinyArrayNonAllocationFunctions.swift | 1 + benchmarks/Sources/VerifierBenchmark.swift | 1 + benchmarks/Sources/blackHole.swift | 31 ------------------- 7 files changed, 11 insertions(+), 32 deletions(-) delete mode 100644 benchmarks/Sources/blackHole.swift diff --git a/benchmarks/Benchmarks/CertificatesBenchmarks/Benchmarks.swift b/benchmarks/Benchmarks/CertificatesBenchmarks/Benchmarks.swift index 4ef00e2..35c7017 100644 --- a/benchmarks/Benchmarks/CertificatesBenchmarks/Benchmarks.swift +++ b/benchmarks/Benchmarks/CertificatesBenchmarks/Benchmarks.swift @@ -16,7 +16,12 @@ import Benchmark import Sources let benchmarks = { - Benchmark("Verifier", configuration: .init(warmupIterations: 1)) { benchmark in + Benchmark.defaultConfiguration = .init( + metrics: [.mallocCountTotal], + warmupIterations: 1 + ) + + Benchmark("Verifier") { benchmark in await verifier() } diff --git a/benchmarks/Package.swift b/benchmarks/Package.swift index b01a9d8..5e8449c 100644 --- a/benchmarks/Package.swift +++ b/benchmarks/Package.swift @@ -28,6 +28,7 @@ let package = Package( .target( name: "Sources", dependencies: [ + .product(name: "Benchmark", package: "package-benchmark"), .product(name: "X509", package: "swift-certificates"), .product(name: "SwiftASN1", package: "swift-asn1"), .product(name: "Crypto", package: "swift-crypto"), diff --git a/benchmarks/Sources/ParseWebPKI.swift b/benchmarks/Sources/ParseWebPKI.swift index 21e21fb..f6ca030 100644 --- a/benchmarks/Sources/ParseWebPKI.swift +++ b/benchmarks/Sources/ParseWebPKI.swift @@ -15,6 +15,7 @@ import X509 import SwiftASN1 import Foundation +import Benchmark public func parseWebPKIRoots() -> () -> Void { let derEncodedCAs = WebPKI.all.map { try! PEMDocument(pemString: $0).derBytes } diff --git a/benchmarks/Sources/TinyArrayAppend.swift b/benchmarks/Sources/TinyArrayAppend.swift index 29482d9..839bca5 100644 --- a/benchmarks/Sources/TinyArrayAppend.swift +++ b/benchmarks/Sources/TinyArrayAppend.swift @@ -13,6 +13,7 @@ //===----------------------------------------------------------------------===// import _CertificateInternals +import Benchmark public func tinyArrayAppend() { var count = 0 diff --git a/benchmarks/Sources/TinyArrayNonAllocationFunctions.swift b/benchmarks/Sources/TinyArrayNonAllocationFunctions.swift index 7c32e22..a42e166 100644 --- a/benchmarks/Sources/TinyArrayNonAllocationFunctions.swift +++ b/benchmarks/Sources/TinyArrayNonAllocationFunctions.swift @@ -13,6 +13,7 @@ //===----------------------------------------------------------------------===// import _CertificateInternals +import Benchmark public func tinyArrayNonAllocationFunctions() { var counts = 0 diff --git a/benchmarks/Sources/VerifierBenchmark.swift b/benchmarks/Sources/VerifierBenchmark.swift index a738925..7631c46 100644 --- a/benchmarks/Sources/VerifierBenchmark.swift +++ b/benchmarks/Sources/VerifierBenchmark.swift @@ -16,6 +16,7 @@ import X509 import Foundation import Crypto import SwiftASN1 +import Benchmark public func verifier() async { var counts = 0 diff --git a/benchmarks/Sources/blackHole.swift b/benchmarks/Sources/blackHole.swift deleted file mode 100644 index d461b4e..0000000 --- a/benchmarks/Sources/blackHole.swift +++ /dev/null @@ -1,31 +0,0 @@ -// ===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2021 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -// ===----------------------------------------------------------------------===// - -/// A function to foil compiler optimizations that would otherwise optimize out code you want to benchmark. -/// -/// The function wraps another object or function, does nothing, and returns. -/// If you want to benchmark the time is takes to create an instance and you don't maintain a reference to it, the compiler may optimize it out entirely, thinking it is unused. -/// To prevent the compiler from removing the code you want to measure, wrap the creation of the instance with `blackHole`. -/// For example, the following code benchmarks the time it takes to create an instance of `Date`, and wraps the creation of the instance to prevent the compiler from optimizing it away: -/// -/// ```swift -/// Benchmark("Foundation Date()", -/// configuration: .init( -/// metrics: [.throughput, .wallClock], -/// scalingFactor: .mega) -/// ) { benchmark in -/// for _ in benchmark.scaledIterations { -/// blackHole(Date()) -/// } -/// } -/// ``` -@inline(never) -public func blackHole(_: some Any) {}