forked from firka/flutter
Merge pull request #276 from abarth/benchmarks
Add some basic benchmarks of the Stocks app
This commit is contained in:
7
packages/flutter_sprites/.gitignore
vendored
7
packages/flutter_sprites/.gitignore
vendored
@@ -1,7 +0,0 @@
|
||||
.DS_Store
|
||||
.idea
|
||||
.packages
|
||||
.pub/
|
||||
build/
|
||||
packages
|
||||
pubspec.lock
|
||||
3
packages/flx/.gitignore
vendored
3
packages/flx/.gitignore
vendored
@@ -1,3 +0,0 @@
|
||||
.idea
|
||||
.pub/
|
||||
pubspec.lock
|
||||
3
packages/unit/.gitignore
vendored
3
packages/unit/.gitignore
vendored
@@ -1,3 +0,0 @@
|
||||
.pub
|
||||
packages
|
||||
pubspec.lock
|
||||
51
packages/unit/benchmark/stocks/animation_bench.dart
Normal file
51
packages/unit/benchmark/stocks/animation_bench.dart
Normal file
@@ -0,0 +1,51 @@
|
||||
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);
|
||||
}
|
||||
43
packages/unit/benchmark/stocks/build_bench.dart
Normal file
43
packages/unit/benchmark/stocks/build_bench.dart
Normal file
@@ -0,0 +1,43 @@
|
||||
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);
|
||||
}
|
||||
40
packages/unit/benchmark/stocks/layout_bench.dart
Normal file
40
packages/unit/benchmark/stocks/layout_bench.dart
Normal file
@@ -0,0 +1,40 @@
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user