Permalink
Browse files

Use stopwatch to profile.

  • Loading branch information...
harrycheung committed Mar 17, 2015
1 parent 2b1b0e6 commit c7a571948c298bb0370bf27e501b3d52eba276b8
@@ -11,6 +11,7 @@
using Android.OS;
using Xamarin.Shared;
using System.Diagnostics;
namespace XamarinAndroid
{
@@ -86,39 +87,47 @@ protected override void OnCreate(Bundle bundle)
label10000 = FindViewById<TextView>(Resource.Id.label10000);
button1000.Click += delegate {
TimeSpan t = DateTime.UtcNow - new DateTime(1970, 1, 1);
int start = (int)t.TotalSeconds;
for (int i = 0; i < 1000; i++) {
t = DateTime.UtcNow - new DateTime(1970, 1, 1);
int startTime = (int)t.TotalSeconds;
SessionManager.Instance().Start(track);
foreach(Point point in points) {
SessionManager.Instance().GPS(point.LatitudeDegrees(), longitude: point.LongitudeDegrees(), speed: point.speed,
bearing: point.bearing, horizontalAccuracy: point.hAccuracy, verticalAccuracy: point.vAccuracy, timestamp: startTime);
startTime += 1;
}
SessionManager.Instance().End();
}
t = DateTime.UtcNow - new DateTime(1970, 1, 1);
label1000.Text = "" + Math.Round(t.TotalSeconds - start, 3);
double timestamp = (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
for (int i = 0; i < 1000; i++) {
SessionManager.Instance().Start(track);
foreach(Point point in points) {
SessionManager.Instance().GPS(point.LatitudeDegrees(),
longitude: point.LongitudeDegrees(),
speed: point.speed,
bearing: point.bearing,
horizontalAccuracy: point.hAccuracy,
verticalAccuracy: point.vAccuracy,
timestamp: timestamp);
timestamp++;
}
SessionManager.Instance().End();
}
stopWatch.Stop();
label1000.Text = String.Format("{0:0.000}", stopWatch.Elapsed.TotalSeconds);
};
button10000.Click += delegate {
TimeSpan t = DateTime.UtcNow - new DateTime(1970, 1, 1);
int start = (int)t.TotalSeconds;
for (int i = 0; i < 10000; i++) {
t = DateTime.UtcNow - new DateTime(1970, 1, 1);
int startTime = (int)t.TotalSeconds;
SessionManager.Instance().Start(track);
foreach(Point point in points) {
SessionManager.Instance().GPS(point.LatitudeDegrees(), longitude: point.LongitudeDegrees(), speed: point.speed,
bearing: point.bearing, horizontalAccuracy: point.hAccuracy, verticalAccuracy: point.vAccuracy, timestamp: startTime);
startTime += 1;
}
SessionManager.Instance().End();
}
t = DateTime.UtcNow - new DateTime(1970, 1, 1);
label10000.Text = "" + Math.Round(t.TotalSeconds - start, 3);
button10000.Click += delegate {
double timestamp = (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
for (int i = 0; i < 10000; i++) {
SessionManager.Instance().Start(track);
foreach(Point point in points) {
SessionManager.Instance().GPS(point.LatitudeDegrees(),
longitude: point.LongitudeDegrees(),
speed: point.speed,
bearing: point.bearing,
horizontalAccuracy: point.hAccuracy,
verticalAccuracy: point.vAccuracy,
timestamp: timestamp);
timestamp++;
}
SessionManager.Instance().End();
}
stopWatch.Stop();
label10000.Text = String.Format("{0:0.000}", stopWatch.Elapsed.TotalSeconds);
};
}
}
@@ -3,8 +3,8 @@
//
using System;
using System.IO;
using System.Collections.Generic;
using System.Diagnostics;
using UIKit;
using Xamarin.Shared;
@@ -78,21 +78,26 @@ public MainViewController (IntPtr handle) : base (handle)
}
private string run(int n)
{
TimeSpan t = DateTime.UtcNow - new DateTime(1970, 1, 1);
int start = (int)t.TotalSeconds;
int startTime = start;
for (int i = 0; i < n; i++) {
t = DateTime.UtcNow - new DateTime(1970, 1, 1);
SessionManager.Instance().Start(track);
foreach(Point point in points) {
SessionManager.Instance().GPS(point.LatitudeDegrees(), longitude: point.LongitudeDegrees(), speed: point.speed, bearing: point.bearing, horizontalAccuracy: point.hAccuracy, verticalAccuracy: point.vAccuracy, timestamp: startTime);
startTime += 1;
}
SessionManager.Instance().End();
}
t = DateTime.UtcNow - new DateTime(1970, 1, 1);
return "" + Math.Round(t.TotalSeconds - start, 3);
{
double timestamp = (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
for (int i = 0; i < n; i++) {
SessionManager.Instance().Start(track);
foreach(Point point in points) {
SessionManager.Instance().GPS(point.LatitudeDegrees(),
longitude: point.LongitudeDegrees(),
speed: point.speed,
bearing: point.bearing,
horizontalAccuracy: point.hAccuracy,
verticalAccuracy: point.vAccuracy,
timestamp: timestamp);
timestamp++;
}
SessionManager.Instance().End();
}
stopWatch.Stop();
return String.Format("{0:0.000}", stopWatch.Elapsed.TotalSeconds);
}
}
}
@@ -41,6 +41,7 @@
<MtouchI18n>
</MtouchI18n>
<CodesignKey>iPhone Developer</CodesignKey>
<MtouchUseRefCounting>true</MtouchUseRefCounting>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
<DebugSymbols>true</DebugSymbols>
@@ -68,7 +69,6 @@
<ConsolePause>false</ConsolePause>
<CodesignKey>iPhone Developer</CodesignKey>
<MtouchUseLlvm>true</MtouchUseLlvm>
<MtouchUseSGen>true</MtouchUseSGen>
<MtouchI18n>
</MtouchI18n>
<MtouchUseThumb>true</MtouchUseThumb>

0 comments on commit c7a5719

Please sign in to comment.