io library
Report files, on platforms with dart:io (not the web): stream tables
into a file with ReportFile, and describe the machine with
environmentSummary.
This library also exports package:microbench/microbench.dart.
Classes
- AsyncBenchmark
- A benchmark whose run is asynchronous. Every run is awaited before the next one starts.
- Benchmark
- A named piece of code to measure.
- BenchmarkChange
- One cell of a comparison, before and after (see BenchmarkDiff).
- BenchmarkDiff
- The differences between two runs of the same comparisons, matched by table title, group, row and column. Times are compared, so any metric works.
- BenchmarkOptions
- How long and how often to time each benchmark.
- BenchmarkSettings
-
Defaults for every comparison started inside apply:
runMainapplies the ones it reads from the command line. - CellStyle
- How a Markdown or HTML cell shows its ranking.
- Comparison
- A measured comparison table: groups of rows, with one column per input.
- ComparisonCell
- One cell of a comparison with its ranking worked out, for renderers.
- ComparisonGroup
- A group of rows compared against each other, such as all libraries that implement one algorithm.
- ComparisonRow
- One row of a ComparisonGroup: a benchmark's results, one per column.
- HtmlTableRenderer
-
Renders an HTML
<table>, with each group name spanning its rows. HTML tables also render inside Markdown files such as a README. - JsonTableRenderer
- Renders each table as one line of JSON (see Comparison.toJson), so a run with several tables writes JSON Lines that parseComparisons reads back. Nothing is written until the table is complete.
- MarkdownTableRenderer
- Renders a GitHub-flavored Markdown table. The group name is shown on the first row of each group.
- Measurement
- The timing result of one benchmark.
- Metric
- What a comparison ranks benchmarks by, and how it prints them.
- ReportFile
- A StringSink that writes to a file, and optionally echoes to stdout.
- SkippedBenchmark
- A placeholder that keeps a row in a comparison without measuring it, for example when a library does not support one column's input. Its cell is left empty and takes no part in the ranking.
- SyncBenchmark
- A benchmark whose run is synchronous.
- TableRenderer
- Turns a Comparison into text, in three parts so a table can be written while it is still being measured: header, one group per group, then footer.
- TextTableRenderer
- Renders aligned plain text for a terminal. Each group is a small table of its own, headed by the group name and the column headers.
Enums
- ChangeKind
- How a benchmark changed between two runs (see BenchmarkDiff).
Functions
-
benchmark(
String name, FutureOr< Object?> run(), {int size = 0, String? column, FutureOr<void> setup()?, FutureOr<void> teardown()?}) → void -
Declares a benchmark of
run, likepackage:test'stest. -
compare(
String name, Map< String, FutureOr< variants, {int size = 0, Metric? metric, BenchmarkOptions? options, bool? verify, double? alpha = 0.05, StringSink? out, TableRenderer? renderer}) → Future<Object?> Function()>Comparison> - Compares closures that do the same work, and prints a table.
-
currentEnvironment(
) → Map< String, String> -
Where the benchmarks run, recorded with every comparison: the runtime
(see detectRuntime); the Dart version, operating system and number of
logical processors when
dart:iocan tell; and the UTC time. -
deepEquals(
Object? a, Object? b) → bool -
Whether
aandbhold equal values, comparing lists (including typed data), sets, maps and other iterables element by element, and anything else with==. AList<int>equals aUint8Listwith the same bytes. -
detectRuntime(
) → String -
How this code runs:
jit(dart run),aot(a compiled executable),js(dart2js) orwasm(dart2wasm). -
environmentSummary(
) → String - One line describing where the benchmarks ran, for a report's footer: the Dart version, operating system and processor count. Benchmark numbers mean little without it.
-
formatBitRate(
num bytesPerSecond) → String -
A byte rate as bits per second in decimal units:
formatBitRate(125000)is1 Mbps. Values of 100 or more in their unit are rounded to whole numbers. -
formatCount(
num value) → String -
A count with a decimal suffix:
formatCount(1234567)is1.23M. -
formatDecimal(
num value, [int precision = 2]) → String -
valuewith at mostprecisiondecimals and no trailing zeros:formatDecimal(1.50)is1.5,formatDecimal(2.0)is2. -
formatDuration(
num micros) → String -
A duration given in microseconds, in the largest fitting unit among
ns,us,msands:formatDuration(1500)is1.5 ms. -
formatSize(
num bytes) → String -
A byte count in binary units:
formatSize(1536)is1.5KB. -
group(
String name, void body()) → void -
Groups the benchmarks declared in
bodyundername, likepackage:test'sgroup. Nested groups join their names with spaces. The benchmarks of a group are compared with the first one in it. -
mannWhitneyP(
List< double> a, List<double> b) → double? -
The two-sided p-value of a Mann-Whitney U test: the probability of seeing
a difference at least this large between
aandbif both came from the same distribution. -
matrix<
T> (String name, {required List< T> cases, required Map<String, FutureOr< variants, String label(T input)?, int size(T input)?, Metric? metric, BenchmarkOptions? options, bool? verify, double? alpha = 0.05, StringSink? out, TableRenderer? renderer}) → Future<Object?> Function(T input)>Comparison> - Compares closures that do the same work across several inputs, and prints a table with one column per input.
-
measureAll(
List< Benchmark> benchmarks, {BenchmarkOptions options = BenchmarkOptions.standard, bool verify = false, bool equals(Object? a, Object? b) = deepEquals}) → Future<List< Measurement?> > -
Measures
benchmarkstogether and returns their results in order, withnullfor each SkippedBenchmark. -
parseComparisons(
String text) → List< Comparison> -
Parses tables written as JSON: one table per line (as
--saveand thejsonformat write them), a JSON array of tables, or a single table. -
ratioText(
double score, double baseline, [String prefix = '', String suffix = '']) → String -
2.5x fasteror2.5x slowerforscoreagainstbaseline, wrapped inprefixandsuffix; empty when either is not positive or they are equal to two decimals. -
runComparison(
{required List< String> columns, required Map<String, List< groups, String? title, String groupHeader = 'Benchmark', String rowHeader = 'Variant', Metric metric = Metric.throughput, int? baseline = 0, double? alpha = 0.05, BenchmarkOptions? options, bool? verify, StringSink? out, TableRenderer? renderer, void onMeasure(String group, Benchmark benchmark, int column, Measurement?)?}) → Future<Benchmark> Function(int column)>Comparison> - Measures a comparison table and returns it.
-
runMain(
List< String> args, FutureOr<void> body()) → Future<void> -
Runs a benchmark program's
bodywith the options inargs, the command line given tomain, and then thebenchmarks it declared.
Exceptions / Errors
- OutputMismatchError
-
Thrown when benchmarks that should compute the same thing return
different results (see the
verifyoption of measureAll).