Port our microbenchmarks to the new world (#4121)
Our microbenchmarks now run on real devices.
9
dev/benchmarks/microbenchmarks/.gitignore
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
.DS_Store
|
||||
.atom/
|
||||
.idea
|
||||
.packages
|
||||
.pub/
|
||||
build/
|
||||
ios/.generated/
|
||||
packages
|
||||
pubspec.lock
|
||||
12
dev/benchmarks/microbenchmarks/README.md
Normal file
@@ -0,0 +1,12 @@
|
||||
# microbenchmarks
|
||||
|
||||
To run these benchmarks on a device:
|
||||
|
||||
```
|
||||
flutter run --release -t lib/gestures/velocity_tracker_data.dart
|
||||
flutter run --release -t lib/stocks/animation_bench.dart
|
||||
flutter run --release -t lib/stocks/build_bench.dart
|
||||
flutter run --release -t lib/stocks/layout_bench.dart
|
||||
```
|
||||
|
||||
The results should be in the device logs.
|
||||
22
dev/benchmarks/microbenchmarks/android/AndroidManifest.xml
Normal file
@@ -0,0 +1,22 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.yourcompany.microbenchmarks"
|
||||
android:versionCode="1"
|
||||
android:versionName="0.0.1">
|
||||
|
||||
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="21" />
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
|
||||
<application android:name="org.domokit.sky.shell.SkyApplication" android:label="microbenchmarks" android:icon="@mipmap/ic_launcher">
|
||||
<activity android:name="org.domokit.sky.shell.SkyActivity"
|
||||
android:launchMode="singleTop"
|
||||
android:theme="@android:style/Theme.Black.NoTitleBar"
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
|
||||
android:hardwareAccelerated="true"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
||||
|
After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 5.7 KiB |
|
After Width: | Height: | Size: 8.7 KiB |
2
dev/benchmarks/microbenchmarks/flutter.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
name: microbenchmarks
|
||||
uses-material-design: true
|
||||
@@ -0,0 +1,142 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"size" : "29x29",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Icon-Small@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "29x29",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Icon-Small@3x.png",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"size" : "40x40",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Icon-Small-40@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "40x40",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Icon-Small-40@3x.png",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"size" : "60x60",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Icon-60@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "60x60",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Icon-60@3x.png",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"size" : "29x29",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "Icon-Small.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "29x29",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "Icon-Small@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "40x40",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "Icon-Small-40.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "40x40",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "Icon-Small-40@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "76x76",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "Icon-76.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "76x76",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "Icon-76@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "83.5x83.5",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "Icon-83.5@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "16x16",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_16x16.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "16x16",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_16x16@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "32x32",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_32x32.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "32x32",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_32x32@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "128x128",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_128x128.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "128x128",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_128x128@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "256x256",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_256x256.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "256x256",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_256x256@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "512x512",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_512x512.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "512x512",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_512x512@2x.png",
|
||||
"scale" : "2x"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
After Width: | Height: | Size: 4.5 KiB |
|
After Width: | Height: | Size: 7.5 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 6.1 KiB |
|
After Width: | Height: | Size: 6.8 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 4.5 KiB |
|
After Width: | Height: | Size: 869 B |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 4.9 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 425 B |
|
After Width: | Height: | Size: 952 B |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 952 B |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 56 KiB |
47
dev/benchmarks/microbenchmarks/ios/Info.plist
Normal file
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>Runner</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.yourcompany.microbenchmarks</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>microbenchmarks</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array>
|
||||
<string>arm64</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations~ipad</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>UIViewControllerBasedStatusBarAppearance</key>
|
||||
<false/>
|
||||
</dict>
|
||||
</plist>
|
||||
27
dev/benchmarks/microbenchmarks/ios/LaunchScreen.storyboard
Normal file
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--View Controller-->
|
||||
<scene sceneID="EHf-IW-A2E">
|
||||
<objects>
|
||||
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
|
||||
<layoutGuides>
|
||||
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
|
||||
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
|
||||
</view>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="53" y="375"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
</document>
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright 2016 The Chromium 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 'dart:io';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'data/velocity_tracker_data.dart';
|
||||
|
||||
const int _kNumIters = 10000;
|
||||
|
||||
void main() {
|
||||
final VelocityTracker tracker = new VelocityTracker();
|
||||
final Stopwatch watch = new Stopwatch();
|
||||
print('Velocity tracker benchmark...');
|
||||
watch.start();
|
||||
for (int i = 0; i < _kNumIters; i += 1) {
|
||||
for (PointerEvent event in velocityEventData) {
|
||||
if (event is PointerDownEvent || event is PointerMoveEvent)
|
||||
tracker.addPosition(event.timeStamp, event.position);
|
||||
if (event is PointerUpEvent)
|
||||
tracker.getVelocity();
|
||||
}
|
||||
}
|
||||
watch.stop();
|
||||
print('Velocity tracker: ${(watch.elapsedMicroseconds / _kNumIters).toStringAsFixed(1)}µs per iteration');
|
||||
exit(0);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
// Copyright 2016 The Chromium 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 'dart:io';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:stocks/main.dart' as stocks;
|
||||
import 'package:stocks/stock_data.dart' as stock_data;
|
||||
|
||||
const Duration kBenchmarkTime = const Duration(seconds: 15);
|
||||
|
||||
class BenchmarkingBinding extends LiveTestWidgetsFlutterBinding {
|
||||
BenchmarkingBinding(this.stopwatch);
|
||||
|
||||
final Stopwatch stopwatch;
|
||||
|
||||
@override
|
||||
void handleBeginFrame(Duration rawTimeStamp) {
|
||||
stopwatch.start();
|
||||
super.handleBeginFrame(rawTimeStamp);
|
||||
stopwatch.stop();
|
||||
}
|
||||
}
|
||||
|
||||
Future<Null> main() async {
|
||||
assert(false); // don't run this in checked mode! Use --release.
|
||||
stock_data.StockDataFetcher.actuallyFetchData = false;
|
||||
|
||||
final Stopwatch wallClockWatch = new Stopwatch();
|
||||
final Stopwatch cpuWatch = new Stopwatch();
|
||||
new BenchmarkingBinding(cpuWatch);
|
||||
|
||||
int totalOpenFrameElapsedMicroseconds = 0;
|
||||
int totalOpenIterationCount = 0;
|
||||
int totalCloseFrameElapsedMicroseconds = 0;
|
||||
int totalCloseIterationCount = 0;
|
||||
int totalSubsequentFramesElapsedMicroseconds = 0;
|
||||
int totalSubsequentFramesIterationCount = 0;
|
||||
|
||||
await benchmarkWidgets((WidgetTester tester) async {
|
||||
stocks.main();
|
||||
await tester.pump(); // Start startup animation
|
||||
await tester.pump(const Duration(seconds: 1)); // Complete startup animation
|
||||
|
||||
bool drawerIsOpen = false;
|
||||
wallClockWatch.start();
|
||||
while (wallClockWatch.elapsed < kBenchmarkTime) {
|
||||
cpuWatch.reset();
|
||||
if (drawerIsOpen) {
|
||||
await tester.tapAt(const Point(780.0, 250.0)); // Close drawer
|
||||
await tester.pump();
|
||||
totalCloseIterationCount += 1;
|
||||
totalCloseFrameElapsedMicroseconds += cpuWatch.elapsedMicroseconds;
|
||||
} else {
|
||||
await tester.tapAt(const Point(20.0, 50.0)); // Open drawer
|
||||
await tester.pump();
|
||||
totalOpenIterationCount += 1;
|
||||
totalOpenFrameElapsedMicroseconds += cpuWatch.elapsedMicroseconds;
|
||||
}
|
||||
drawerIsOpen = !drawerIsOpen;
|
||||
|
||||
// Time how long each frame takes
|
||||
cpuWatch.reset();
|
||||
while (SchedulerBinding.instance.hasScheduledFrame) {
|
||||
await tester.pump();
|
||||
totalSubsequentFramesIterationCount += 1;
|
||||
}
|
||||
totalSubsequentFramesElapsedMicroseconds += cpuWatch.elapsedMicroseconds;
|
||||
}
|
||||
});
|
||||
|
||||
print('Stock animation (ran for ${(wallClockWatch.elapsedMicroseconds / (1000 * 1000)).toStringAsFixed(1)}s):');
|
||||
print(' Opening first frame average time: ${(totalOpenFrameElapsedMicroseconds / (totalOpenIterationCount)).toStringAsFixed(1)}µs per frame ($totalOpenIterationCount frames)');
|
||||
print(' Closing first frame average time: ${(totalCloseFrameElapsedMicroseconds / (totalCloseIterationCount)).toStringAsFixed(1)}µs per frame ($totalCloseIterationCount frames)');
|
||||
print(' Subsequent frames average time: ${(totalSubsequentFramesElapsedMicroseconds / (totalSubsequentFramesIterationCount)).toStringAsFixed(1)}µs per frame ($totalSubsequentFramesIterationCount frames)');
|
||||
|
||||
exit(0);
|
||||
}
|
||||
43
dev/benchmarks/microbenchmarks/lib/stocks/build_bench.dart
Normal file
@@ -0,0 +1,43 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:stocks/main.dart' as stocks;
|
||||
import 'package:stocks/stock_data.dart' as stock_data;
|
||||
|
||||
const Duration kBenchmarkTime = const Duration(seconds: 15);
|
||||
|
||||
void _doNothing() { }
|
||||
|
||||
Future<Null> main() async {
|
||||
assert(false); // don't run this in checked mode! Use --release.
|
||||
stock_data.StockDataFetcher.actuallyFetchData = false;
|
||||
|
||||
final Stopwatch watch = new Stopwatch();
|
||||
int iterations = 0;
|
||||
|
||||
await benchmarkWidgets((WidgetTester tester) async {
|
||||
stocks.main();
|
||||
await tester.pump(); // Start startup animation
|
||||
await tester.pump(const Duration(seconds: 1)); // Complete startup animation
|
||||
await tester.tapAt(new Point(20.0, 20.0)); // Open drawer
|
||||
await tester.pump(); // Start drawer animation
|
||||
await tester.pump(const Duration(seconds: 1)); // Complete drawer animation
|
||||
|
||||
|
||||
final stocks.StocksAppState appState = tester.state(find.byType(stocks.StocksApp));
|
||||
final BuildOwner buildOwner = WidgetsBinding.instance.buildOwner;
|
||||
|
||||
watch.start();
|
||||
while (watch.elapsed < kBenchmarkTime) {
|
||||
appState.setState(_doNothing);
|
||||
buildOwner.buildDirtyElements();
|
||||
iterations += 1;
|
||||
}
|
||||
watch.stop();
|
||||
});
|
||||
|
||||
print('Stock build: ${(watch.elapsedMicroseconds / iterations).toStringAsFixed(1)}µs per iteration');
|
||||
exit(0);
|
||||
}
|
||||
43
dev/benchmarks/microbenchmarks/lib/stocks/layout_bench.dart
Normal file
@@ -0,0 +1,43 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:stocks/main.dart' as stocks;
|
||||
import 'package:stocks/stock_data.dart' as stock_data;
|
||||
|
||||
const Duration kBenchmarkTime = const Duration(seconds: 15);
|
||||
|
||||
|
||||
|
||||
Future<Null> main() async {
|
||||
assert(false); // don't run this in checked mode! Use --release.
|
||||
stock_data.StockDataFetcher.actuallyFetchData = false;
|
||||
|
||||
final Stopwatch watch = new Stopwatch();
|
||||
int iterations = 0;
|
||||
|
||||
await benchmarkWidgets((WidgetTester tester) async {
|
||||
stocks.main();
|
||||
await tester.pump(); // Start startup animation
|
||||
await tester.pump(const Duration(seconds: 1)); // Complete startup animation
|
||||
await tester.tapAt(new Point(20.0, 20.0)); // Open drawer
|
||||
await tester.pump(); // Start drawer animation
|
||||
await tester.pump(const Duration(seconds: 1)); // Complete drawer animation
|
||||
|
||||
final TestViewConfiguration big = new TestViewConfiguration(size: const Size(360.0, 640.0));
|
||||
final TestViewConfiguration small = new TestViewConfiguration(size: const Size(355.0, 635.0));
|
||||
final RenderView renderView = WidgetsBinding.instance.renderView;
|
||||
|
||||
watch.start();
|
||||
while (watch.elapsed < kBenchmarkTime) {
|
||||
renderView.configuration = (iterations % 2 == 0) ? big : small;
|
||||
RendererBinding.instance.pipelineOwner.flushLayout();
|
||||
iterations += 1;
|
||||
}
|
||||
watch.stop();
|
||||
});
|
||||
|
||||
print('Stock layout: ${(watch.elapsedMicroseconds / iterations).toStringAsFixed(1)}µs per iteration');
|
||||
exit(0);
|
||||
}
|
||||
9
dev/benchmarks/microbenchmarks/pubspec.yaml
Normal file
@@ -0,0 +1,9 @@
|
||||
name: microbenchmarks
|
||||
description: A new flutter project.
|
||||
dependencies:
|
||||
flutter:
|
||||
path: ../../../packages/flutter
|
||||
flutter_test:
|
||||
path: ../../../packages/flutter_test
|
||||
stocks:
|
||||
path: ../../../examples/stocks
|
||||