error(_:)
Used to signify that a given benchmark have failed for some reason
func error(_ description: String) Parameters
- description
An explanation why a given benchmark failed which will be reported to the end user.
Used to signify that a given benchmark have failed for some reason
func error(_ description: String) An explanation why a given benchmark failed which will be reported to the end user.
import BenchmarkBenchmark allows you to easily create sophisticated Swift performance benchmarks
final class BenchmarkDefines a benchmark
@frozen struct StringA Unicode string value that is a collection of characters.
var name: String { get set }The name used for display purposes of the benchmark (also used for matching when comparing to baselines)
var currentIteration: IntThe current benchmark iteration (also includes warmup iterations), can be useful when e.g. unique keys will be needed for different iterations
var failureReason: String?The reason for a benchmark failure, not set if successful
@discardableResult convenience init?(_ name: String, configuration: Benchmark.Configuration = Benchmark.defaultConfiguration, closure: @escaping Benchmark.BenchmarkThrowingClosure, setup: Benchmark.BenchmarkSetupHook? = nil, teardown: Benchmark.BenchmarkTeardownHook? = nil) Definition of a throwing Benchmark
@discardableResult convenience init?(_ name: String, configuration: Benchmark.Configuration = Benchmark.defaultConfiguration, closure: @escaping Benchmark.BenchmarkAsyncThrowingClosure, setup: Benchmark.BenchmarkSetupHook? = nil, teardown: Benchmark.BenchmarkTeardownHook? = nil) Definition of an async throwing Benchmark
@discardableResult init?(_ name: String, configuration: Benchmark.Configuration = Benchmark.defaultConfiguration, closure: @escaping Benchmark.BenchmarkAsyncClosure, setup: Benchmark.BenchmarkSetupHook? = nil, teardown: Benchmark.BenchmarkTeardownHook? = nil) Definition of a Benchmark
@discardableResult convenience init?<SetupResult>(_ name: String, configuration: Benchmark.Configuration = Benchmark.defaultConfiguration, closure: @escaping (Benchmark, SetupResult) throws -> Void, setup: @escaping () async throws -> SetupResult, teardown: Benchmark.BenchmarkTeardownHook? = nil) Definition of a throwing Benchmark
@discardableResult convenience init?<SetupResult>(_ name: String, configuration: Benchmark.Configuration = Benchmark.defaultConfiguration, closure: @escaping (Benchmark, SetupResult) async throws -> Void, setup: @escaping () async throws -> SetupResult, teardown: Benchmark.BenchmarkTeardownHook? = nil) Definition of an async throwing Benchmark
@discardableResult convenience init?<SetupResult>(_ name: String, configuration: Benchmark.Configuration = Benchmark.defaultConfiguration, closure: @escaping (Benchmark, SetupResult) async -> Void, setup: @escaping () async throws -> SetupResult, teardown: Benchmark.BenchmarkTeardownHook? = nil) Definition of an async Benchmark
@discardableResult convenience init?<SetupResult>(_ name: String, configuration: Benchmark.Configuration = Benchmark.defaultConfiguration, closure: @escaping (Benchmark, SetupResult) -> Void, setup: @escaping () async throws -> SetupResult, teardown: Benchmark.BenchmarkTeardownHook? = nil) Definition of a Benchmark
@discardableResult init?(_ name: String, configuration: Benchmark.Configuration = Benchmark.defaultConfiguration, closure: @escaping Benchmark.BenchmarkClosure, setup: Benchmark.BenchmarkSetupHook? = nil, teardown: Benchmark.BenchmarkTeardownHook? = nil) Definition of a Benchmark
init(from decoder: any Decoder) throws @ThreadSafeProperty static var _setup: Benchmark.BenchmarkSetupHook? { get set }@ThreadSafeProperty static var _shutdownHook: Benchmark.BenchmarkTeardownHook? { get set }@ThreadSafeProperty static var _startupHook: Benchmark.BenchmarkSetupHook? { get set }@ThreadSafeProperty static var _teardown: Benchmark.BenchmarkTeardownHook? { get set }static var benchmarks: [Benchmark]nonisolated(unsafe) static var defaultConfiguration: Benchmark.Configuration { get set }nonisolated(unsafe) static var setup: Benchmark.BenchmarkSetupHook? { get set }This closure if set, will be run before a targets benchmarks are run, but after they are registered
nonisolated(unsafe) static var shutdownHook: Benchmark.BenchmarkTeardownHook? { get set }nonisolated(unsafe) static var startupHook: Benchmark.BenchmarkSetupHook? { get set }nonisolated(unsafe) static var teardown: Benchmark.BenchmarkTeardownHook? { get set }This closure if set, will be run after a targets benchmarks run, but after they are registered
static func blackHole(_: some Any) A function to foil compiler optimizations that would otherwise optimize out code you want to benchmark.
var baseName: StringThe name of the benchmark without any of the tags appended
var configuration: Benchmark.ConfigurationThe configuration to use for this benchmark
var customMetricMeasurement: Benchmark.BenchmarkCustomMetricMeasurement?var executablePath: String?var measurementPostSynchronization: Benchmark.BenchmarkMeasurementSynchronization?var measurementPreSynchronization: Benchmark.BenchmarkMeasurementSynchronization?var scaledIterations: Range<Int> { get }Convenience range to iterate over for benchmarks
var setupState: Any?The state returned from setup, if any - need to be cast as required
var target: StringSome internal state for display purposes of the benchmark by the BenchmarkTool
static func == (lhs: Benchmark, rhs: Benchmark) -> Bool func hash(into hasher: inout Hasher) func measurement(_ metric: BenchmarkMetric, _ value: Int) measurement registers custom metric measurements
func run() func startMeasurement() If the benchmark contains a preamble setup that should not be part of the measurement startMeasurement can be called explicitly to define when measurement should begin. Otherwise the whole benchmark will be measured.
func stopMeasurement() If the benchmark contains a postample that should not be part of the measurement stopMeasurement can be called explicitly to define when measurement should stop. Otherwise the whole benchmark will be measured.
struct ConfigurationThe configuration settings for running a benchmark.
typealias BenchmarkAsyncClosure = (Benchmark) async -> Voidtypealias BenchmarkAsyncThrowingClosure = (Benchmark) async throws -> Voidtypealias BenchmarkClosure = (Benchmark) -> Voidtypealias BenchmarkCustomMetricMeasurement = (BenchmarkMetric, Int) -> Voidtypealias BenchmarkMeasurementSynchronization = (Bool) -> Voidtypealias BenchmarkSetupHook = () async throws -> VoidAlias for closures used to hook into setup / teardown
typealias BenchmarkTeardownHook = () async throws -> Voidtypealias BenchmarkThrowingClosure = (Benchmark) throws -> Voidstatic var checkAbsoluteThresholds: BoolSet to true if this benchmark results should be compared with an absolute threshold when --check-absolute is specified on the command line. An implementation can then choose to configure thresholds differently for such comparisons by e.g. reading them in from external storage.