From 004283d7b628a29fcf711d98d8842bfd4ef4393b Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 17 Oct 2018 12:02:19 +0200 Subject: [PATCH] Add perf test case. --- .gitignore | 1 + AppDelegate.cs | 44 +++++++++++++++++++++++++++++++++++++++++ Makefile | 11 ++++++++++- testcode.m | 29 +++++++++++++++++++++++++++ unified-test-app.csproj | 12 ++++++++--- 5 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 testcode.m diff --git a/.gitignore b/.gitignore index 90ade4b..30f0dae 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +*.o bin obj *.userprefs diff --git a/AppDelegate.cs b/AppDelegate.cs index 9877162..1af1b9d 100644 --- a/AppDelegate.cs +++ b/AppDelegate.cs @@ -1,4 +1,6 @@ using System; +using System.Diagnostics; +using System.Runtime.InteropServices; using Foundation; using UIKit; @@ -9,6 +11,32 @@ public class AppDelegate : UIApplicationDelegate UIWindow window; UIViewController dvc; + static long totalMS; + static long iterations; + + void Run () + { + IntPtr array; + const int counter = 10000; + GC.Collect (); + createArguments (out array, counter); + try { + var watch = Stopwatch.StartNew (); + callSelector (Handle, array, counter); + watch.Stop (); + var lastAvg = totalMS / (double) iterations; + totalMS += watch.ElapsedMilliseconds; + iterations++; + var avg = totalMS / (double) iterations; + Console.WriteLine ("Did {0} iterations in {1}ms (average: {2:0.00}ms of {3} iterations, diff since last: {4:0.00})", + counter, watch.ElapsedMilliseconds, avg, iterations, avg - lastAvg); + } finally { + freeArguments (array, counter); + } + GC.Collect (); + NSTimer.CreateScheduledTimer (0.1, (v) => Run ()); + } + public override bool FinishedLaunching (UIApplication app, NSDictionary options) { window = new UIWindow (UIScreen.MainScreen.Bounds); @@ -16,6 +44,8 @@ public override bool FinishedLaunching (UIApplication app, NSDictionary options) dvc.View.BackgroundColor = UIColor.White; window.MakeKeyAndVisible (); + NSTimer.CreateScheduledTimer (0.1, (v) => Run ()); + return true; } @@ -23,4 +53,18 @@ static void Main (string[] args) { UIApplication.Main (args, null, typeof (AppDelegate)); } + + [Export ("callMe:")] + void CallMe (UIView view) + { + } + + [DllImport ("__Internal")] + extern static void callSelector (IntPtr handle, IntPtr args, int counter); + + [DllImport ("__Internal")] + extern static void createArguments (out IntPtr array, int counter); + + [DllImport ("__Internal")] + extern static void freeArguments (IntPtr array, int counter); } diff --git a/Makefile b/Makefile index 82dd6fc..93be7b6 100644 --- a/Makefile +++ b/Makefile @@ -11,4 +11,13 @@ archive: dev: /Library/Frameworks/Mono.framework/Commands/xbuild /p:Platform=iPhone /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch --installdev bin/iPhone/Debug/*.app - /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch --launchdev $(shell /usr/libexec/PlistBuddy -c 'Print CFBundleIdentifier' bin/iPhone/Debug/*.app/Info.plist) \ No newline at end of file + /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch --launchdev $(shell /usr/libexec/PlistBuddy -c 'Print CFBundleIdentifier' bin/iPhone/Debug/*.app/Info.plist) + +libtestcode.o: libtestcode.dev.o libtestcode.sim.o + lipo -create -output $@ $? + +libtestcode.dev.o: testcode.m Makefile + clang -arch arm64 -c $< -o$@ -mios-simulator-version-min=6.0 -isysroot /Applications/Xcode10.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk + +libtestcode.sim.o: testcode.m Makefile + clang -arch x86_64 -c $< -o$@ -miphoneos-version-min=6.0 -isysroot /Applications/Xcode10.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk \ No newline at end of file diff --git a/testcode.m b/testcode.m new file mode 100644 index 0000000..43c0fef --- /dev/null +++ b/testcode.m @@ -0,0 +1,29 @@ +#include +#include + +@interface CallMe : NSObject +-(void) callMe: (NSObject *) obj; +@end + +void +callSelector (CallMe *obj, NSObject **args, int counter) +{ + for (int i = 0; i < counter; i++) + [obj callMe: args [i]]; +} + +void +createArguments (NSObject ***array, int counter) +{ + *array = calloc (sizeof (NSObject *), counter + 1); + for (int i = 0; i < counter; i++) + (*array) [i] = [[UIView alloc] init]; +} + +void +freeArguments (NSObject **array, int counter) +{ + for (int i = 0; i < counter; i++) + [array [i] release]; + free (array); +} diff --git a/unified-test-app.csproj b/unified-test-app.csproj index efa7ff7..78042e4 100644 --- a/unified-test-app.csproj +++ b/unified-test-app.csproj @@ -24,11 +24,12 @@ x86_64 True true - --registrar:static --optimize:all + --gcc_flags -Wl,libtestcode.o Full true iPhone Developer false + HttpClientHandler none @@ -41,6 +42,7 @@ true x86_64 + HttpClientHandler True @@ -54,11 +56,12 @@ True True ARM64 - + --gcc_flags -Wl,libtestcode.o true Full true false + HttpClientHandler False @@ -69,13 +72,16 @@ True ARM64 true - + --gcc_flags -Wl,libtestcode.o true Full + HttpClientHandler + true +