Unverified Commit e6aa6ce2 authored by Abhishek Ghaskata's avatar Abhishek Ghaskata Committed by GitHub

migrate platform channels benchmarks (#84066)

parent bcc8f083
...@@ -12,8 +12,8 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -12,8 +12,8 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:microbenchmarks/common.dart'; import 'package:microbenchmarks/common.dart';
List<Object> _makeTestBuffer(int size) { List<Object?> _makeTestBuffer(int size) {
final List<Object> answer = <Object>[]; final List<Object?> answer = <Object?>[];
for (int i = 0; i < size; ++i) { for (int i = 0; i < size; ++i) {
switch (i % 9) { switch (i % 9) {
case 0: case 0:
...@@ -49,7 +49,7 @@ List<Object> _makeTestBuffer(int size) { ...@@ -49,7 +49,7 @@ List<Object> _makeTestBuffer(int size) {
} }
Future<double> _runBasicStandardSmall( Future<double> _runBasicStandardSmall(
BasicMessageChannel<Object> basicStandard, int count) async { BasicMessageChannel<Object?> basicStandard, int count) async {
final Stopwatch watch = Stopwatch(); final Stopwatch watch = Stopwatch();
watch.start(); watch.start();
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
...@@ -59,14 +59,14 @@ Future<double> _runBasicStandardSmall( ...@@ -59,14 +59,14 @@ Future<double> _runBasicStandardSmall(
return watch.elapsedMicroseconds / count; return watch.elapsedMicroseconds / count;
} }
Future<double> _runBasicStandardLarge(BasicMessageChannel<Object> basicStandard, Future<double> _runBasicStandardLarge(BasicMessageChannel<Object?> basicStandard,
List<Object> largeBuffer, int count) async { List<Object?> largeBuffer, int count) async {
int size = 0; int size = 0;
final Stopwatch watch = Stopwatch(); final Stopwatch watch = Stopwatch();
watch.start(); watch.start();
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
final List<Object> result = final List<Object?>? result =
await basicStandard.send(largeBuffer) as List<Object>; await basicStandard.send(largeBuffer) as List<Object?>?;
// This check should be tiny compared to the actual channel send/receive. // This check should be tiny compared to the actual channel send/receive.
size += (result == null) ? 0 : result.length; size += (result == null) ? 0 : result.length;
} }
...@@ -87,7 +87,7 @@ Future<double> _runBasicBinary(BasicMessageChannel<ByteData> basicBinary, ...@@ -87,7 +87,7 @@ Future<double> _runBasicBinary(BasicMessageChannel<ByteData> basicBinary,
final Stopwatch watch = Stopwatch(); final Stopwatch watch = Stopwatch();
watch.start(); watch.start();
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
final ByteData result = await basicBinary.send(buffer); final ByteData? result = await basicBinary.send(buffer);
// This check should be tiny compared to the actual channel send/receive. // This check should be tiny compared to the actual channel send/receive.
size += (result == null) ? 0 : result.lengthInBytes; size += (result == null) ? 0 : result.lengthInBytes;
} }
...@@ -108,11 +108,11 @@ Future<void> _runTests() async { ...@@ -108,11 +108,11 @@ Future<void> _runTests() async {
); );
} }
const BasicMessageChannel<Object> resetChannel = BasicMessageChannel<Object>( const BasicMessageChannel<Object?> resetChannel = BasicMessageChannel<Object?>(
'dev.flutter.echo.reset', 'dev.flutter.echo.reset',
StandardMessageCodec(), StandardMessageCodec(),
); );
const BasicMessageChannel<Object> basicStandard = BasicMessageChannel<Object>( const BasicMessageChannel<Object?> basicStandard = BasicMessageChannel<Object?>(
'dev.flutter.echo.basic.standard', 'dev.flutter.echo.basic.standard',
StandardMessageCodec(), StandardMessageCodec(),
); );
...@@ -125,9 +125,9 @@ Future<void> _runTests() async { ...@@ -125,9 +125,9 @@ Future<void> _runTests() async {
/// WARNING: Don't change the following line of code, it will invalidate /// WARNING: Don't change the following line of code, it will invalidate
/// `Large` tests. Instead make a different test. The size of largeBuffer /// `Large` tests. Instead make a different test. The size of largeBuffer
/// serialized is 14214 bytes. /// serialized is 14214 bytes.
final List<Object> largeBuffer = _makeTestBuffer(1000); final List<Object?> largeBuffer = _makeTestBuffer(1000);
final ByteData largeBufferBytes = final ByteData largeBufferBytes =
const StandardMessageCodec().encodeMessage(largeBuffer); const StandardMessageCodec().encodeMessage(largeBuffer)!;
final ByteData oneMB = ByteData(1024 * 1024); final ByteData oneMB = ByteData(1024 * 1024);
const int numMessages = 2500; const int numMessages = 2500;
...@@ -170,7 +170,7 @@ Future<void> _runTests() async { ...@@ -170,7 +170,7 @@ Future<void> _runTests() async {
} }
class _BenchmarkWidget extends StatefulWidget { class _BenchmarkWidget extends StatefulWidget {
const _BenchmarkWidget(this.tests, {Key key}) : super(key: key); const _BenchmarkWidget(this.tests, {Key? key}) : super(key: key);
final Future<void> Function() tests; final Future<void> Function() tests;
......
...@@ -5,7 +5,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev ...@@ -5,7 +5,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1 version: 1.0.0+1
environment: environment:
sdk: ">=2.9.0 <3.0.0" sdk: ">=2.12.0 <3.0.0"
dependencies: dependencies:
flutter: flutter:
......
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