-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(minor): Add Benchmark parameters
Sometimes it is convenient to run the same benchmark multiple times under slightly different scenarios. For example, benchmarking `func foo(_ n: Int)` for various parameterizations of `n`. This adds support for specifying the parameters of a benchmark but makes no functional changes beyond the name/identifier of a benchmark now including a parameter list when one was provided. This unlocks the potential for the benchmark exporters (such as the Influx exporter) to leverage these parameters (by emitting appropriate tags/fields in the case of Influx) in their output.
- Loading branch information
Jairon Terrero
committed
Sep 16, 2024
1 parent
75e8622
commit c957cba
Showing
3 changed files
with
100 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
|
||
/// Represents a parameter used to define the implementation of a benchmark. | ||
/// Useful for running the same benchmark under a set of unique scenarios. | ||
/// | ||
/// For example, running multiple benchmarks of `func foo(_ n:Int)` | ||
/// for various parameterizations of `n`. | ||
public struct BenchmarkParameter: Codable { | ||
public let name: String | ||
|
||
/// Describes the range of possible values for this parameter. | ||
public let range: Range | ||
public enum Range: Codable { case finite, infinite } | ||
|
||
public let value: Value | ||
|
||
/// Represents a value that may be one of a set of allowed types. | ||
public enum Value: Codable { | ||
case string(String) | ||
case int(Int) | ||
case double(Double) | ||
} | ||
|
||
public init(_ name: String, _ value: Value, range: Range) { | ||
self.name = name | ||
self.value = value | ||
self.range = range | ||
} | ||
} | ||
|
||
extension BenchmarkParameter.Value: CustomStringConvertible { | ||
public var description: String { | ||
switch self { | ||
case let .string(string): | ||
string | ||
case let .int(int): | ||
int.description | ||
case let .double(double): | ||
double.description | ||
} | ||
} | ||
} | ||
|
||
|
||
extension BenchmarkParameter.Value: ExpressibleByStringLiteral { | ||
public init(stringLiteral value: StringLiteralType) { | ||
self = .string(value) | ||
} | ||
} | ||
extension BenchmarkParameter.Value: ExpressibleByIntegerLiteral { | ||
public init(integerLiteral value: IntegerLiteralType) { | ||
self = .int(value) | ||
} | ||
} | ||
extension BenchmarkParameter.Value: ExpressibleByFloatLiteral { | ||
public init(floatLiteral value: FloatLiteralType) { | ||
self = .double(value) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters