Skip to content

Commit 5e0f1db

Browse files
committed
Rename functions warmup* -> warmUp*
1 parent c1c8163 commit 5e0f1db

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,17 +211,18 @@ total benchmark run times within acceptable limits.
211211
<details> <summary> Click to show details. </summary>
212212

213213
In a first step, benchmark scores are estimated using the
214-
functions [`warmup`][warmup]
215-
or [`warmupAsync`][warmupAsync]. The function [`BenchmarkHelper.sampleSize`][sampleSize]
216-
uses the score estimate to determine the sampling procedure.
214+
functions [`warmUp`][warmUp]
215+
or [`warmUpAsync`][warmUpAsync]. The function [`BenchmarkHelper.sampleSize`][sampleSize]
216+
uses the score estimate to determine the sample size and the number of inner
217+
iterations (for short run times each sample entry is averaged).
217218

218219
### 1. Default Sampling Method
219220
The graph below shows the sample size (orange curve) as calculated by the function
220221
[`BenchmarkHelper.sampleSize`][sampleSize].
221222
The green curve shows the lower limit of the total microbenchmark duration and
222223
represents the value: `clockTicks * sampleSize * innerIterations`.
223224

224-
![Sample Size](https://raw.githubusercontent.com/simphotonics/benchmark_runner/main/images/sample_size.png)
225+
![Sample Size](https://raw.githubusercontent.com/simphotonics/benchmark_runner/custom-emitter/images/sample_size.png)
225226

226227
For short run times below 100000 clock ticks each sample score is generated
227228
using the functions [`measure`][measure] or the equivalent asynchronous method [`measureAsync`][measureAsync].
@@ -238,7 +239,7 @@ averaged over (see the cyan curve in the graph above):
238239
To custominze the score sampling process, the static function
239240
[`BenchmarkHelper.sampleSize`][sampleSize] can be replaced with a custom function:
240241
```Dart
241-
/// Generates a sample containing 100 benchmark scores.
242+
/// Generates a sample containing 100 benchmark scores.
242243
BenchmarkHelper.sampleSize = (int clockTicks) {
243244
return (outer: 100, inner: 1)
244245
}
@@ -300,6 +301,6 @@ Please file feature requests and bugs at the [issue tracker][tracker].
300301

301302
[sampleSize]: https://pub.dev/documentation/benchmark_runner/latest/benchmark_runner/BenchmarkHelper/sampleSize.html
302303

303-
[warmup]: https://pub.dev/documentation/benchmark_runner/latest/benchmark_runner/BenchmarkHelper/warmup.html
304+
[warmUp]: https://pub.dev/documentation/benchmark_runner/latest/benchmark_runner/BenchmarkHelper/warmUp.html
304305

305-
[warmupAsync]: https://pub.dev/documentation/benchmark_runner/latest/benchmark_runner/BenchmarkHelper/warmupAsync.html
306+
[warmUpAsync]: https://pub.dev/documentation/benchmark_runner/latest/benchmark_runner/BenchmarkHelper/warmUpAsync.html

lib/src/extension/benchmark_helper.dart

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ extension BenchmarkHelper on Stopwatch {
3838

3939
/// Measures the runtime of [f] for [duration] and
4040
/// reports the average runtime expressed as clock ticks.
41-
({int ticks, int iter}) warmup(
41+
({int ticks, int iter}) warmUp(
4242
void Function() f, {
4343
Duration duration = const Duration(milliseconds: 200),
44-
int preRuns = 3,
44+
int warmUpRuns = 3,
4545
}) {
46-
var ticks = microsecondsToTicks(duration.inMicroseconds);
47-
var iter = 0;
48-
for (var i = 0; i < preRuns; i++) {
46+
int ticks = durationToTicks(duration);
47+
int iter = 0;
48+
for (var i = 0; i < warmUpRuns; i++) {
4949
f();
5050
}
5151
reset();
@@ -59,15 +59,15 @@ extension BenchmarkHelper on Stopwatch {
5959

6060
/// Measures the runtime of [f] for [duration] and
6161
/// reports the average runtime expressed as clock ticks.
62-
Future<({int ticks, int iter})> warmupAsync(
62+
Future<({int ticks, int iter})> warmUpAsync(
6363
Future<void> Function() f, {
6464
Duration duration = const Duration(milliseconds: 200),
65-
int preRuns = 3,
65+
int warmUpRuns = 3,
6666
}) async {
67-
var ticks = microsecondsToTicks(duration.inMicroseconds);
68-
var iter = 0;
67+
int ticks = durationToTicks(duration);
68+
int iter = 0;
6969
reset();
70-
for (var i = 0; i < preRuns; i++) {
70+
for (var i = 0; i < warmUpRuns; i++) {
7171
await f();
7272
}
7373
start();
@@ -84,6 +84,10 @@ extension BenchmarkHelper on Stopwatch {
8484
/// Converts clock [ticks] to seconds.
8585
static double ticksToSeconds(int ticks) => ticks / BenchmarkHelper.frequency;
8686

87+
/// Convert [duration] to clock ticks.
88+
static int durationToTicks(Duration duration) =>
89+
microsecondsToTicks(duration.inMicroseconds);
90+
8791
/// Converts clock [ticks] to microseconds.
8892
static double ticksToMicroseconds(int ticks) =>
8993
ticks / (BenchmarkHelper.frequency / 1000000);
@@ -124,8 +128,8 @@ extension BenchmarkHelper on Stopwatch {
124128
/// * number of runs each score is averaged over: `.inner`.
125129
///
126130
/// Note: An estimate of the benchmark runtime in clock ticks is given by
127-
/// `outer*inner*clockTicks`. The estimate does not include any setup, warmup,
128-
/// or teardown functionality.
131+
/// `outer*inner*clockTicks`. The estimate does not include any setup,
132+
/// warm-up, or teardown functionality.
129133
static ({int outer, int inner}) sampleSizeDefault(int clockTicks) {
130134
// Estimates for the averaging used within `measure` and `measureAsync.
131135

0 commit comments

Comments
 (0)