Commit 68eebaa5 authored by Adam Barth's avatar Adam Barth

Add some basic benchmarks of the Stocks app

 - animation_bench.dart. This benchmark measures the full main-thread pipeline
   for ticking the drawer entrance and exit animation.
 - build_bench.dart. This benchmark measures a full app rebuild when there's no
   state change.
 - layout_bench.dart. This benchmark measures a full relayout.
parent 778289f7
.DS_Store
.idea
.packages
.pub/
build/
packages
pubspec.lock
.idea
.pub/
pubspec.lock
.pub
packages
pubspec.lock
import 'dart:io';
import 'package:flutter/rendering.dart';
import 'package:flutter/material.dart';
import 'package:stocks/main.dart' as stocks;
import 'package:stocks/stock_data.dart' as stock_data;
import '../../test/widget/widget_tester.dart';
const int _kNumberOfIterations = 50000;
const bool _kRunForever = true;
void main() {
assert(false); // Don't run in checked mode
stock_data.StockDataFetcher.actuallyFetchData = false;
const Duration _kAnimationDuration = const Duration(milliseconds: 200);
const Duration tickDuration = const Duration(milliseconds: 2);
int numberOfTicks = _kAnimationDuration.inMicroseconds ~/ tickDuration.inMicroseconds;
int numberOfRounts = _kNumberOfIterations ~/ numberOfTicks;
Stopwatch watch = new Stopwatch()
..start();
testWidgets((WidgetTester tester) {
stocks.main();
tester.pump(); // Start startup animation
tester.pump(const Duration(seconds: 1)); // Complete startup animation
bool drawerIsOpen = false;
for (int i = 0; i < numberOfRounts || _kRunForever; ++i) {
if (drawerIsOpen)
tester.tapAt(const Point(20.0, 20.0)); // Open drawer
else
tester.tapAt(const Point(780.0, 20.0)); // Close drawer
tester.pump(); // Start drawer animation
for (int j = 0; j < numberOfTicks; ++j)
tester.pump(tickDuration);
tester.pump(const Duration(seconds: 1)); // Complete animation
drawerIsOpen = !drawerIsOpen;
}
});
watch.stop();
print("Stock animation: " + watch.elapsed.toString());
exit(0);
}
import 'dart:io';
import 'package:flutter/rendering.dart';
import 'package:flutter/material.dart';
import 'package:stocks/main.dart' as stocks;
import 'package:stocks/stock_data.dart' as stock_data;
import '../../test/widget/widget_tester.dart';
const int _kNumberOfIterations = 100000;
const bool _kRunForever = true;
void _doNothing() { }
void main() {
assert(false); // Don't run in checked mode
stock_data.StockDataFetcher.actuallyFetchData = false;
stocks.StocksAppState appState;
testWidgets((WidgetTester tester) {
stocks.main();
tester.pump(); // Start startup animation
tester.pump(const Duration(seconds: 1)); // Complete startup animation
tester.tapAt(new Point(20.0, 20.0)); // Open drawer
tester.pump(); // Start drawer animation
tester.pump(const Duration(seconds: 1)); // Complete drawer animation
appState = tester.findStateOfType(stocks.StocksAppState);
});
WidgetFlutterBinding binding = WidgetFlutterBinding.instance;
Stopwatch watch = new Stopwatch()
..start();
for (int i = 0; i < _kNumberOfIterations || _kRunForever; ++i) {
appState.setState(_doNothing);
binding.buildDirtyElements();
}
watch.stop();
print("Stock build: " + watch.elapsed.toString());
exit(0);
}
import 'dart:io';
import 'package:flutter/rendering.dart';
import 'package:flutter/material.dart';
import 'package:stocks/main.dart' as stocks;
import 'package:stocks/stock_data.dart' as stock_data;
import '../../test/widget/widget_tester.dart';
const int _kNumberOfIterations = 100000;
const bool _kRunForever = false;
void main() {
assert(false); // Don't run in checked mode
stock_data.StockDataFetcher.actuallyFetchData = false;
testWidgets((WidgetTester tester) {
stocks.main();
tester.pump(); // Start startup animation
tester.pump(const Duration(seconds: 1)); // Complete startup animation
tester.tapAt(new Point(20.0, 20.0)); // Open drawer
tester.pump(); // Start drawer animation
tester.pump(const Duration(seconds: 1)); // Complete drawer animation
});
ViewConstraints big = const ViewConstraints(size: const Size(360.0, 640.0));
ViewConstraints small = const ViewConstraints(size: const Size(355.0, 635.0));
RenderView renderView = WidgetFlutterBinding.instance.renderView;
Stopwatch watch = new Stopwatch()
..start();
for (int i = 0; i < _kNumberOfIterations || _kRunForever; ++i) {
renderView.rootConstraints = (i % 2 == 0) ? big : small;
RenderObject.flushLayout();
}
watch.stop();
print("Stock layout: " + watch.elapsed.toString());
exit(0);
}
......@@ -6,5 +6,7 @@ dependencies:
path: ../flx
flutter:
path: ../flutter
stocks:
path: ../../examples/stocks
sky_tools:
path: ../flutter_tools
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