Created
February 15, 2018 16:20
-
-
Save jonathanpeppers/f586938eb39734c194c2690fb6035403 to your computer and use it in GitHub Desktop.
Static profiler class for timing different intervals across a Xamarin.Forms app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Concurrent; | |
using System.Diagnostics; | |
namespace xfperf | |
{ | |
public static class Profiler | |
{ | |
static readonly ConcurrentDictionary<string, Stopwatch> watches = new ConcurrentDictionary<string, Stopwatch>(); | |
public static void Start(object view) | |
{ | |
Start(view.GetType().Name); | |
} | |
public static void Start(string tag) | |
{ | |
Console.WriteLine("Starting Stopwatch {0}", tag); | |
var watch = | |
watches[tag] = new Stopwatch(); | |
watch.Start(); | |
} | |
public static void Stop(string tag) | |
{ | |
Stopwatch watch; | |
if (watches.TryGetValue(tag, out watch)) | |
{ | |
Console.WriteLine("Stopwatch {0} took {1}", tag, watch.Elapsed); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment