Add a microbenchmark that measures performance of flutter compute. (#91257)
* Add a microbenchmark that measures performance of flutter compute. This benchmark should show performance improvements when compute is switched to Isolate.exit * Fix analyzer warnings, increase warmup iterations * Fix license header
This commit is contained in:
parent
35fe52cb86
commit
98120d19d3
@ -0,0 +1,49 @@
|
|||||||
|
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
|
||||||
|
import '../common.dart';
|
||||||
|
|
||||||
|
const int _kNumIterations = 10;
|
||||||
|
const int _kNumWarmUp = 100;
|
||||||
|
|
||||||
|
class Data {
|
||||||
|
Data(this.value);
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => <String, dynamic>{ 'value': value };
|
||||||
|
|
||||||
|
final int value;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Data> test(int length) {
|
||||||
|
return List<Data>.generate(length,
|
||||||
|
(int index) => Data(index * index));
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> main() async {
|
||||||
|
assert(false, "Don't run benchmarks in checked mode! Use 'flutter run --release'.");
|
||||||
|
|
||||||
|
// Warm up lap
|
||||||
|
for (int i = 0; i < _kNumWarmUp; i += 1) {
|
||||||
|
await compute(test, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
final Stopwatch watch = Stopwatch();
|
||||||
|
watch.start();
|
||||||
|
for (int i = 0; i < _kNumIterations; i += 1) {
|
||||||
|
await compute(test, 1000000);
|
||||||
|
}
|
||||||
|
final int elapsedMicroseconds = watch.elapsedMicroseconds;
|
||||||
|
|
||||||
|
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
|
||||||
|
const double scale = 1000.0 / _kNumIterations;
|
||||||
|
printer.addResult(
|
||||||
|
description: 'compute',
|
||||||
|
value: elapsedMicroseconds * scale,
|
||||||
|
unit: 'ns per iteration',
|
||||||
|
name: 'compute_iteration',
|
||||||
|
);
|
||||||
|
printer.printToStdout();
|
||||||
|
}
|
@ -54,6 +54,7 @@ TaskFunction createMicrobenchmarkTask() {
|
|||||||
...await _runMicrobench('lib/gestures/velocity_tracker_bench.dart'),
|
...await _runMicrobench('lib/gestures/velocity_tracker_bench.dart'),
|
||||||
...await _runMicrobench('lib/gestures/gesture_detector_bench.dart'),
|
...await _runMicrobench('lib/gestures/gesture_detector_bench.dart'),
|
||||||
...await _runMicrobench('lib/stocks/animation_bench.dart'),
|
...await _runMicrobench('lib/stocks/animation_bench.dart'),
|
||||||
|
...await _runMicrobench('lib/language/compute_bench.dart'),
|
||||||
...await _runMicrobench('lib/language/sync_star_bench.dart'),
|
...await _runMicrobench('lib/language/sync_star_bench.dart'),
|
||||||
...await _runMicrobench('lib/language/sync_star_semantics_bench.dart'),
|
...await _runMicrobench('lib/language/sync_star_semantics_bench.dart'),
|
||||||
...await _runMicrobench('lib/foundation/all_elements_bench.dart'),
|
...await _runMicrobench('lib/foundation/all_elements_bench.dart'),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user