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.
// 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/microbench.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);
});
}