Skip to content

Benchmarking

microbench

Benchmarks you can compare, check for noise and publish, in a zero-dependency Dart package.


Latest releasev0.4.0

Published Dec 4, 2026 · 1 day ago

$dart pub add dev:microbench
Downloads (30 days)
0
Likes
1
pub points
160/160
GitHub stars
1

Runs on

  • Android
  • iOS
  • Windows
  • Linux
  • macOS
  • Web
  • Wasm
bitanon/microbenchSponsor on GitHub

Quickstart

Install it, import it, and you are ready. This example comes straight from the README on the repository’s default branch, so it never drifts from the docs.

More recipes in the guide
main.dart
import 'package:microbench/suite.dart';

void main() {
  group('Repeat one char, 1000 times', () {
    benchmark('+ operator', () {
      var s = '';
      for (var i = 0; i < 1000; i++) {
        s += 'x';
      }
      return s;
    });
    benchmark('StringBuffer', () {
      final sb = StringBuffer();
      for (var i = 0; i < 1000; i++) {
        sb.write('x');
      }
      return sb.toString();
    });
    benchmark('* operator', () => 'x' * 1000);
  });
}

What's new in next

Changelog →
  • Breaking Changes: Measurement.runtimeMicros is the 10th percentile of the samples, not the median. Interference only ever slows a batch, so the low end repeats across runs (0.06% spread against 0.14% for the median). bestMicros, worstMicros, meanMicros, cv and the samples are unchanged.
  • Breaking Changes: BenchmarkOptions.warmup is the least warmup time; it now lasts until the per-call time stops improving, since a fixed warmup can end while the JIT is still speeding the code up, which made two runs of one benchmark differ by a percent or more.
  • Breaking Changes: batching follows the run's length: a run slower than batchTarget is measured one per batch, and a batch too fast to time grows until it is measurable.
  • Breaking Changes: duration is now the longest time spent measuring. The exercise phase stops as soon as the low end has settled for BenchmarkOptions.minSamples batches (new, default 40), so a run usually finishes well before it: --standard on a small benchmark dropped from about 2.1 s to 0.3-1.5 s with the same answer. Raise minSamples to always spend the full duration.
  • BenchmarkSettings.formats names a TableRenderer, so --format=NAME and --out=FILE.NAME reach a custom renderer in runMain.
  • compare, matrix and runComparison in a plain void main() pick up the runner's options (--quick, --filter, --format, --verify).
  • benchmarkColumns(name, {column: run}, sizes: [...]) declares one row measured in several columns, in a suite.
  • test_integration/: a public-API smoke test, run on the VM and on node.

next0.4.00.3.10.3.00.2.00.1.0