Skip to content

Instantly share code, notes, and snippets.

@letsar
Created November 30, 2020 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save letsar/ebc99e00540e60d3ec99636108e52e6a to your computer and use it in GitHub Desktop.
Save letsar/ebc99e00540e60d3ec99636108e52e6a to your computer and use it in GitHub Desktop.
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