Unverified Commit 7c3f79f7 authored by gaaclarke's avatar gaaclarke Committed by GitHub

Added performance benchmarks to background platform channels for iOS. (#97991)

parent b6232790
// Copyright 2014 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 <Foundation/Foundation.h>
#import <Flutter/Flutter.h>
NS_ASSUME_NONNULL_BEGIN
@interface AppDelegate : FlutterAppDelegate
@end
NS_ASSUME_NONNULL_END
// Copyright 2014 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 "AppDelegate.h"
@import Flutter;
#import "GeneratedPluginRegistrant.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey, id> *)launchOptions {
[GeneratedPluginRegistrant registerWithRegistry:self];
NSObject<FlutterPluginRegistrar>* registrar = [self registrarForPlugin:@"Echo"];
FlutterBasicMessageChannel* reset = [[FlutterBasicMessageChannel alloc] initWithName:@"dev.flutter.echo.reset" binaryMessenger:registrar.messenger codec:FlutterStandardMessageCodec.sharedInstance];
[reset setMessageHandler:^(id _Nullable message, FlutterReply _Nonnull callback) {
// noop
}];
FlutterBasicMessageChannel* basicStandard = [[FlutterBasicMessageChannel alloc] initWithName:@"dev.flutter.echo.basic.standard" binaryMessenger:registrar.messenger codec:FlutterStandardMessageCodec.sharedInstance];
[basicStandard setMessageHandler:^(id _Nullable message, FlutterReply _Nonnull callback) {
callback(message);
}];
FlutterBasicMessageChannel* basicBinary = [[FlutterBasicMessageChannel alloc] initWithName:@"dev.flutter.echo.basic.binary" binaryMessenger:registrar.messenger codec:FlutterBinaryCodec.sharedInstance];
[basicBinary setMessageHandler:^(id _Nullable message, FlutterReply _Nonnull callback) {
callback(message);
}];
NSObject<FlutterTaskQueue>* taskQueue = [registrar.messenger makeBackgroundTaskQueue];
FlutterBasicMessageChannel* background =
[[FlutterBasicMessageChannel alloc] initWithName:@"dev.flutter.echo.background.standard" binaryMessenger:registrar.messenger codec:FlutterStandardMessageCodec.sharedInstance taskQueue:taskQueue];
[background setMessageHandler:^(id _Nullable message, FlutterReply _Nonnull callback) {
callback(message);
}];
return YES;
}
@end
// Copyright 2014 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 Flutter
import UIKit
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
let registrar = self.registrar(forPlugin: "Echo")!
let reset = FlutterBasicMessageChannel(
name: "dev.flutter.echo.reset", binaryMessenger: registrar.messenger())
reset.setMessageHandler { (input, reply) in
// noop
}
let basicStandard = FlutterBasicMessageChannel(
name: "dev.flutter.echo.basic.standard", binaryMessenger: registrar.messenger(),
codec: FlutterStandardMessageCodec.sharedInstance())
basicStandard.setMessageHandler { (input, reply) in
reply(input)
}
let basicBinary = FlutterBasicMessageChannel(
name: "dev.flutter.echo.basic.binary", binaryMessenger: registrar.messenger(),
codec: FlutterBinaryCodec())
basicBinary.setMessageHandler { (input, reply) in
reply(input)
}
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
// Copyright 2014 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 <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[]) {
NSString * appDelegateClassName;
@autoreleasepool {
// Setup code that might create autoreleased objects goes here.
appDelegateClassName = NSStringFromClass([AppDelegate class]);
}
return UIApplicationMain(argc, argv, nil, appDelegateClassName);
}
......@@ -3,7 +3,6 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:io' show Platform;
import 'dart:math' as math;
import 'dart:typed_data';
......@@ -161,6 +160,7 @@ Future<void> _runTest({
required String name,
required int numMessages,
}) async {
print('running $name');
resetChannel.send(true);
// Prime test.
await test(1);
......@@ -247,33 +247,30 @@ Future<void> _runTests() async {
name: 'platform_channel_basic_standard_2host_small_parallel_3',
numMessages: numMessages,
);
if (Platform.isAndroid) {
// Background platform channels aren't yet implemented for iOS.
const BasicMessageChannel<Object?> backgroundStandard =
BasicMessageChannel<Object?>(
'dev.flutter.echo.background.standard',
StandardMessageCodec(),
);
await _runTest(
test: (int x) => _runBasicStandardSmall(backgroundStandard, x),
resetChannel: resetChannel,
printer: printer,
description:
'BasicMessageChannel/StandardMessageCodec/Flutter->Host (background)/Small',
name: 'platform_channel_basic_standard_2hostbackground_small',
numMessages: numMessages,
);
await _runTest(
test: (int x) =>
_runBasicStandardParallel(backgroundStandard, x, 1234, 3),
resetChannel: resetChannel,
printer: printer,
description:
'BasicMessageChannel/StandardMessageCodec/Flutter->Host (background)/SmallParallel3',
name: 'platform_channel_basic_standard_2hostbackground_small_parallel_3',
numMessages: numMessages,
);
}
// Background platform channels aren't yet implemented for iOS.
const BasicMessageChannel<Object?> backgroundStandard =
BasicMessageChannel<Object?>(
'dev.flutter.echo.background.standard',
StandardMessageCodec(),
);
await _runTest(
test: (int x) => _runBasicStandardSmall(backgroundStandard, x),
resetChannel: resetChannel,
printer: printer,
description:
'BasicMessageChannel/StandardMessageCodec/Flutter->Host (background)/Small',
name: 'platform_channel_basic_standard_2hostbackground_small',
numMessages: numMessages,
);
await _runTest(
test: (int x) => _runBasicStandardParallel(backgroundStandard, x, 1234, 3),
resetChannel: resetChannel,
printer: printer,
description:
'BasicMessageChannel/StandardMessageCodec/Flutter->Host (background)/SmallParallel3',
name: 'platform_channel_basic_standard_2hostbackground_small_parallel_3',
numMessages: numMessages,
);
printer.printToStdout();
}
......
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