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: runMain applies 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, like package:test's test.
compare(String name, Map<String, FutureOr<Object?> Function()> variants, {int size = 0, Metric? metric, BenchmarkOptions? options, bool? verify, double? alpha = 0.05, StringSink? out, TableRenderer? renderer}) → Future<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:io can tell; and the UTC time.
deepEquals(Object? a, Object? b) → bool
Whether a and b hold equal values, comparing lists (including typed data), sets, maps and other iterables element by element, and anything else with ==. A List<int> equals a Uint8List with the same bytes.
detectRuntime() → String
How this code runs: jit (dart run), aot (a compiled executable), js (dart2js) or wasm (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) is 1 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) is 1.23M.
formatDecimal(num value, [int precision = 2]) → String
value with at most precision decimals and no trailing zeros: formatDecimal(1.50) is 1.5, formatDecimal(2.0) is 2.
formatDuration(num micros) → String
A duration given in microseconds, in the largest fitting unit among ns, us, ms and s: formatDuration(1500) is 1.5 ms.
formatSize(num bytes) → String
A byte count in binary units: formatSize(1536) is 1.5KB.
group(String name, void body()) → void
Groups the benchmarks declared in body under name, like package:test's group. 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 a and b if both came from the same distribution.
matrix<T>(String name, {required List<T> cases, required Map<String, FutureOr<Object?> Function(T input)> variants, String label(T input)?, int size(T input)?, Metric? metric, BenchmarkOptions? options, bool? verify, double? alpha = 0.05, StringSink? out, TableRenderer? renderer}) → Future<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 benchmarks together and returns their results in order, with null for each SkippedBenchmark.
parseComparisons(String text) → List<Comparison>
Parses tables written as JSON: one table per line (as --save and the json format write them), a JSON array of tables, or a single table.
ratioText(double score, double baseline, [String prefix = '', String suffix = '']) → String
2.5x faster or 2.5x slower for score against baseline, wrapped in prefix and suffix; empty when either is not positive or they are equal to two decimals.
runComparison({required List<String> columns, required Map<String, List<Benchmark> Function(int column)> 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<Comparison>
Measures a comparison table and returns it.
runMain(List<String> args, FutureOr<void> body()) → Future<void>
Runs a benchmark program's body with the options in args, the command line given to main, and then the benchmarks it declared.

Exceptions / Errors

OutputMismatchError
Thrown when benchmarks that should compute the same thing return different results (see the verify option of measureAll).