microbench 0.5.0
microbench: ^0.5.0 copied to clipboard
Zero-dependency microbenchmark harness for Dart: accurate timing, comparison tables in Markdown, HTML or text, and regression checks for CI.
0.5.0 #
One import, one command, and a rebuilt measurement engine.
- 💥 [Breaking Changes]
- Requires Dart 3.0. Value types (
Measurement,BenchmarkOptions,Metric,Comparisonand its parts,BenchmarkSettings,CellStyle,BenchmarkDiff,BenchmarkChange,SkippedBenchmark) arefinal. package:microbench/microbench.dartis the only import;suite.dartis merged into it (withpackage:test, hide onegroup).runSuite->runMain.runRegisteredandbenchmarkColumnsare removed: declare a row over several inputs withbenchmark(..., column:)in a loop.- Removed
embedFile,compileAndRun, themicrobench:embedandmicrobench:exeexecutables, and the exported command-line internals (parseSettings,environmentSettings,runMainUsage,programOptionValues,settingsFromArgs, the runner). BenchmarkOptionsiswarmup(the minimum),batchTarget(10 ms),samples(40),roundsandduration(a cap for slow benchmarks);minBatch,minSamplesandbatchSizeare removed.Measurement.runtimeMicrosis the 10th percentile of the samples, not the median.Measurement.rounds->Measurement.runs, in JSON too.measureRateandmeasureDiffshow throughput when the benchmark has asize, else the rate;metricoverrides it.- Arguments after
--reach the program after a--, whererunMainstops reading options.
- Requires Dart 3.0. Value types (
- ⚙️ [Engine]
- A comparison's benchmarks are verified before warmup, warm up in turns through one shared timing loop made megamorphic first, and record a fixed number of samples over alternating rounds.
- On the JIT, identical benchmarks measured up to 23% apart and now agree
within 1%. A default run takes 1.5-3 times less time. See
guides/how-it-works.md.
- ✨ [Improvements]
- Tables warn when a cell's batches vary by more than 10%, and
diffwarns when the two runs differ in runtime, Dart version or OS. BenchmarkSettings.formatsregisters aTableRendererfor--formatand--out.measureDifftakesalpha;ComparisonGrouptakesbaseline.parseComparisonsthrows aFormatExceptionfor JSON that is not tables, such as a file saved by 0.4.0, instead of a null-check error.compare,matrixandrunComparisonin a plainmain()read the runner's options.- Guides rewritten from beginner to advanced, with a new one on how the engine measures.
- Tables warn when a cell's batches vary by more than 10%, and
- 🐛 [Fixes]
- The
jstarget crashed with "self is not defined" on any program that uses a timer, including every suite. - An invalid
--filterregular expression was ignored instead of exiting with usage. - Declarations after an
awaitin arunMainbody could run before the body finished. - Markdown and HTML cells always show their ratio to the baseline, with
🔶 after it for noise. A ratio that rounded to
1xshowed 🌟 instead, and a noise cell showed only≈.
- The
0.4.0 #
- Pass benchmark options directly to the runner, for example
dart run microbench --quick --filter=UTF8. Use--to forward custom arguments to benchmark programs. - When the runner finds no benchmarks, it shows a starter file and the command to run it.
- Filtered comparisons keep each group's original baseline, including when reloaded from a saved report. Filtering out the baseline hides its ratios.
microbench diffdistinguishes labels containing/and reports an error if two cells have the same title, group, row, and column.parseComparisonsaccepts indented JSON reports as well as compact JSON and JSON Lines.measureAllruns every open session's teardown, even if one throws, and preserves the first failure and its stack trace.- If a benchmark process fails to start, the runner continues with the remaining programs and targets and exits with a failure status.
0.3.1 #
- A benchmark whose batches outlast the whole
duration(runs of seconds) now sits out the remaining rounds, as before rounds existed, instead of running at least one batch in every round.
0.3.0 #
- Breaking Changes:
dart run microbenchwith no command now runs the benchmarks underbenchmark/instead of printing usage (exit code 64), and a first word that is not a command is taken as a path;runMainkeeps settings from an enclosingBenchmarkSettings.applythat its arguments do not override. runSuite(args, body): command-line options for benchmarks declared withbenchmark()andgroup().- Benchmarks declared in a plain
void main()read options from theMICROBENCH_ARGSenvironment variable, whichdart run microbenchnow sets, sodart run microbench <file> -- --quickworks withoutrunSuite. runMaintakes any setting its arguments leave out from an enclosingBenchmarkSettings.apply.- Warmup no longer runs for tens of seconds when a run is shorter than a clock tick: it is timed on one running stopwatch instead of a sum of per-run readings that rounded to 0.
dart run microbenchruns benchmarks without theruncommand name, which stays as an alias.
0.2.0 #
- Breaking Changes: text tables mark noise with
(≈ same)and end with warnings; Markdown and HTML cells may end with≈;MeasurementJSON gainssampleMicros; comparisons measure their rows in alternating rounds, so timings shift slightly from 0.1.0. compareandmatrix: comparison tables from maps of closures, sync or async.package:microbench/suite.dart:benchmark()andgroup(), declared likepackage:testand run automatically.runMain(args, body):--quick,--thorough,--filter,--format,--out,--verify,--save,--baselineand--thresholdfor any benchmark program, through zone-scopedBenchmarkSettings.- Rows of a column are measured in alternating rounds (A B B A);
BenchmarkOptions.roundsandBenchmarkOptions.thorough.measureAllmeasures a list of benchmarks this way. - Significance:
Measurementkeeps its samples (sampleMicros,meanMicros,stdDevMicros,cv); cells whose difference fails a Mann-Whitney U test (mannWhitneyP,runComparison(alpha:)) are marked≈, also inmeasureDiff. - Warnings below tables for runs under 1 ns and times that do not grow with
the input size (
Comparison.warnings,showWarnings:). verify:oncompare,matrix,runComparison,measureAllandmeasureDiffchecks that rows return equal results (deepEquals), throwingOutputMismatchError.JsonTableRenderer,Comparison.fromJson,parseComparisons,Metric.byName, andBenchmarkDiffwithChangeKindfor regression checks.- Tables record their
environment(detectRuntime(),currentEnvironment()). dart run microbench runcompiles and runs benchmarks onjit,aot,jsandwasm(runBenchmarks,planRun,findBenchmarks), anddart run microbench diffcompares saved results.- Guides: getting trustworthy numbers, and migrating from
benchmark_harness. - Bars no longer fail when a run is faster than the clock resolution, and
infinite values format as
Infinity.
0.1.0 #
- Initial release, extracted from the benchmark harness shared by hashlib, cipherlib and convertlib.
SyncBenchmark,AsyncBenchmarkandSkippedBenchmark, withSyncBenchmark.fromandAsyncBenchmark.fromfor closures.BenchmarkOptionsfor warmup, duration and batch sizing.Measurementwith median, best, worst and median absolute deviation, and JSON support.Metric.throughput,Metric.rate,Metric.runtimeandMetric.perSecond.runComparisonandComparison, rendered byMarkdownTableRenderer,HtmlTableRendererandTextTableRenderer, or serialized withtoJson.package:microbench/io.dart:ReportFile,embedFile,compileAndRunandenvironmentSummary.- Executables
microbench:embedandmicrobench:exe.