Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import 'package:benchmark_harness/benchmark_harness.dart';
abstract class Benchmark extends BenchmarkBase {
const Benchmark(String name) : super(name);
@override
void exercise() {
for (int i = 0; i < 100000; i++) {
run();
}
}
}
class FixedLengthListBenchmark extends Benchmark {
const FixedLengthListBenchmark(this.length) : super('fixed-length[$length]');
final int length;
@override
void run() {
List<int>()..length = length;
}
}
class GrowableListBenchmark extends Benchmark {
const GrowableListBenchmark(this.length) : super('growable[$length]');
final int length;
@override
void run() {
List(length);
}
}
void main() {
const GrowableListBenchmark(32).report();
const FixedLengthListBenchmark(32).report();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment