New benchmark: Gesture semantics (#35232)
* Add semanticsEnabled to widgetBenchmark * Add button_matrix_app and gesture benchmark
This commit is contained in:
@@ -6,6 +6,7 @@ these:
|
||||
|
||||
```
|
||||
flutter run --release lib/gestures/velocity_tracker_data.dart
|
||||
flutter run --release lib/gestures/gesture_detector_bench.dart
|
||||
flutter run --release lib/stocks/animation_bench.dart
|
||||
flutter run --release lib/stocks/build_bench.dart
|
||||
flutter run --release lib/stocks/layout_bench.dart
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
// Copyright 2019 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/material.dart';
|
||||
|
||||
class ButtonMatrixApp extends StatefulWidget {
|
||||
@override
|
||||
ButtonMatrixAppState createState() => ButtonMatrixAppState();
|
||||
}
|
||||
|
||||
class ButtonMatrixAppState extends State<ButtonMatrixApp> {
|
||||
|
||||
int count = 1;
|
||||
int increment = 1;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
home: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Count: $count'),
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
onPressed: () => setState(() { count += increment; }),
|
||||
child: Text('Add $increment'),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: List<Widget>.filled(
|
||||
3,
|
||||
Column(
|
||||
children: List<Widget>.filled(
|
||||
10,
|
||||
FlatButton(
|
||||
child: const Text('Faster'),
|
||||
onPressed: () => setState(() { increment += 1; }),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
runApp(ButtonMatrixApp());
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// Copyright 2019 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/gestures.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../common.dart';
|
||||
import './apps/button_matrix_app.dart' as button_matrix;
|
||||
|
||||
const int _kNumWarmUpIters = 20;
|
||||
const int _kNumIters = 300;
|
||||
|
||||
Future<void> main() async {
|
||||
assert(false, "Don't run benchmarks in checked mode! Use 'flutter run --release'.");
|
||||
final Stopwatch watch = Stopwatch();
|
||||
print('GestureDetector semantics benchmark...');
|
||||
|
||||
await benchmarkWidgets((WidgetTester tester) async {
|
||||
button_matrix.main();
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
|
||||
Future<void> iter() async {
|
||||
// Press a button to update the screen
|
||||
await tester.tapAt(const Offset(760.0, 30.0));
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
// Warm up runs get the app into steady state, making benchmark
|
||||
// results more credible
|
||||
for (int i = 0; i < _kNumWarmUpIters; i += 1) {
|
||||
await iter();
|
||||
}
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
watch.start();
|
||||
for (int i = 0; i < _kNumIters; i += 1) {
|
||||
await iter();
|
||||
}
|
||||
watch.stop();
|
||||
}, semanticsEnabled: true);
|
||||
|
||||
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
|
||||
printer.addResult(
|
||||
description: 'GestureDetector',
|
||||
value: watch.elapsedMicroseconds / _kNumIters,
|
||||
unit: 'µs per iteration',
|
||||
name: 'gesture_detector_bench',
|
||||
);
|
||||
printer.printToStdout();
|
||||
}
|
||||
@@ -53,6 +53,7 @@ TaskFunction createMicrobenchmarkTask() {
|
||||
allResults.addAll(await _runMicrobench('lib/stocks/build_bench.dart'));
|
||||
allResults.addAll(await _runMicrobench('lib/geometry/rrect_contains_bench.dart'));
|
||||
allResults.addAll(await _runMicrobench('lib/gestures/velocity_tracker_bench.dart'));
|
||||
allResults.addAll(await _runMicrobench('lib/gestures/gesture_detector_bench.dart'));
|
||||
allResults.addAll(await _runMicrobench('lib/stocks/animation_bench.dart'));
|
||||
|
||||
return TaskResult.success(allResults, benchmarkScoreKeys: allResults.keys.toList());
|
||||
|
||||
Reference in New Issue
Block a user