Skip to content

Commit

Permalink
Add perf test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfbjarne committed Oct 17, 2018
1 parent fea250c commit 004283d
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.o
bin
obj
*.userprefs
Expand Down
44 changes: 44 additions & 0 deletions AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

using Foundation;
using UIKit;
Expand All @@ -9,18 +11,60 @@ 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);
window.RootViewController = dvc = new UIViewController ();
dvc.View.BackgroundColor = UIColor.White;
window.MakeKeyAndVisible ();

NSTimer.CreateScheduledTimer (0.1, (v) => Run ());

return true;
}

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);
}
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
/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
29 changes: 29 additions & 0 deletions testcode.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <Foundation/Foundation.h>
#include <UIKit/UIKit.h>

@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);
}
12 changes: 9 additions & 3 deletions unified-test-app.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
<MtouchArch>x86_64</MtouchArch>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<MtouchProfiling>true</MtouchProfiling>
<MtouchExtraArgs>--registrar:static --optimize:all</MtouchExtraArgs>
<MtouchExtraArgs>--gcc_flags -Wl,libtestcode.o</MtouchExtraArgs>
<MtouchLink>Full</MtouchLink>
<MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
<CodesignKey>iPhone Developer</CodesignKey>
<DeviceSpecificBuild>false</DeviceSpecificBuild>
<MtouchHttpClientHandler>HttpClientHandler</MtouchHttpClientHandler>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
<DebugType>none</DebugType>
Expand All @@ -41,6 +42,7 @@
<MtouchDebug>true</MtouchDebug>
<MtouchExtraArgs></MtouchExtraArgs>
<MtouchArch>x86_64</MtouchArch>
<MtouchHttpClientHandler>HttpClientHandler</MtouchHttpClientHandler>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
<DebugSymbols>True</DebugSymbols>
Expand All @@ -54,11 +56,12 @@
<MtouchDebug>True</MtouchDebug>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<MtouchArch>ARM64</MtouchArch>
<MtouchExtraArgs></MtouchExtraArgs>
<MtouchExtraArgs>--gcc_flags -Wl,libtestcode.o</MtouchExtraArgs>
<MtouchProfiling>true</MtouchProfiling>
<MtouchLink>Full</MtouchLink>
<MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
<DeviceSpecificBuild>false</DeviceSpecificBuild>
<MtouchHttpClientHandler>HttpClientHandler</MtouchHttpClientHandler>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
<Optimize>False</Optimize>
Expand All @@ -69,13 +72,16 @@
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<MtouchArch>ARM64</MtouchArch>
<DebugSymbols>true</DebugSymbols>
<MtouchExtraArgs></MtouchExtraArgs>
<MtouchExtraArgs>--gcc_flags -Wl,libtestcode.o</MtouchExtraArgs>
<MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
<MtouchLink>Full</MtouchLink>
<MtouchHttpClientHandler>HttpClientHandler</MtouchHttpClientHandler>
<MtouchUseLlvm>true</MtouchUseLlvm>
</PropertyGroup>
<ItemGroup>
<Reference Include="Xamarin.iOS" />
<Reference Include="System.Core" />
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<None Include="Info.plist" />
Expand Down

0 comments on commit 004283d

Please sign in to comment.