Skip to content

Instantly share code, notes, and snippets.

@jonathanpeppers
Created February 15, 2018 16:20
Show Gist options
  • Save jonathanpeppers/f586938eb39734c194c2690fb6035403 to your computer and use it in GitHub Desktop.
Save jonathanpeppers/f586938eb39734c194c2690fb6035403 to your computer and use it in GitHub Desktop.
Static profiler class for timing different intervals across a Xamarin.Forms app
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