Unverified Commit 98120d19 authored by Alexander Aprelev's avatar Alexander Aprelev Committed by GitHub

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
parent 35fe52cb
// 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/gesture_detector_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_semantics_bench.dart'),
...await _runMicrobench('lib/foundation/all_elements_bench.dart'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment