I'd like to refactor BenchmarkInfo
used in Swift Benchmarking Suite (SBS) to better match the emergent style of writing benchmarks.
I think the current order of attributes in BenchmarkInfo
is a bit unfortunate. The runFunction
is currently sandwiched in the middle of attribute list. I'd like to make it the last parameter, so that we can use trailing closure syntax for writing the body of performance test directly after the declaration. This eliminates boilerplate of declaring separate one-use function, decorating it with @inline(never)
attribute and referring to it in the declaration.
If the benchmark function can be reused between multiple benchmarks, where they each perform their own workload specific setUp
, it of course makes sense to have shared run function which is referred to by name. See ExistentialPerformance.swift for a recent example of this style.
Here's the sketch of the proposed design in action:
Benchmark("Name",
info: "Optional one line description of the benchmarks purpose ") {
for _ in 1...100 {
workload
}
}
Benchmark("Name",
aka: "OldName", legacyFactor: 10,
setUp: { … }, tearDown: { … }) {
for _ in 1...100 {
workload
}
}
Benchmark("Name", setUp: { prepareWorkload(size: 123}, run: doTheStuff)
// func doTheStuf is the run function shared between multiple benchmarks
In the Benchmark Naming Convention discussion was suggested addition of a one-line description attribute to better document the benchmark's purpose. I'm putting it here as optional info
parameter after the name
(actually after the legacyFactor
).
The existing parameter legacyFactor
and the proposed aka
are part of a strategy to transition to robust performance measurements without disrupting the long-term performance tracking. I'm slowly finishing the final passes through SBS:
- eliminating setup overhead and lowering the runtimes under 1000 μs and
- setting
legacyFactor
to fake the original results.
After introducing the aka
I want to rename the benchmarks that have specified legacyFactor
and double report the results from Benchmark_O
:
- under
name
with actual measurements - under
aka
with measurements multiplied bylegacyFactor
There will be option (--no-legacy
?) to turn off the double reporting, which will be use in Benchmark_Driver
. But the default double reporting is there to allow the internal long term performance tracking LNT
server to pick up long enough history, so that we may remove it in the future (Swift 6, 7?).
I'd also like to retire the BenchmarkCategory
also known as tags
in favor of an optional skip: Bool
, as I think tags are a bit over-engineered and unused in practice.
As you can see there are quite a few moving parts and I'd like to get your feedback before moving forward.