/list_benchmark.dart Secret
Created
November 30, 2020 21:08
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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