Skip to main content

microbench 0.3.1 copy "microbench: ^0.3.1" to clipboard
microbench: ^0.3.1 copied to clipboard

Zero-dependency microbenchmark harness for Dart: robust timing, comparison tables in Markdown, HTML or text, JSON output, and README embedding.

example/example.dart

// Copyright (c) 2026, Sudipto Chandra
// All rights reserved. Check LICENSE file for details.

// Three ways to build a string, measured side by side.
//
//   dart run microbench example/example.dart -- --quick
//
// The other files in this folder show the other ways to use microbench.

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);
  });
}
1
likes
0
points
0
downloads

Publisher

verified publisherbitanon.dev

Weekly Downloads

Zero-dependency microbenchmark harness for Dart: robust timing, comparison tables in Markdown, HTML or text, JSON output, and README embedding.

Repository (GitHub)
View/report issues

Topics

#benchmark #performance #profiling #testing

Funding

Consider supporting this project:

paypal.me

License

unknown (license)

More

Packages that depend on microbench