Created
May 11, 2018 23:09
-
-
Save ericvoid/20d26de1d410c93211e28b256fa356bd to your computer and use it in GitHub Desktop.
Simple C# Profiler
This file contains 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
public class MyProfiler | |
{ | |
public int Calls | |
{ | |
get; | |
private set; | |
} | |
public TimeSpan TotalTime | |
{ | |
get; | |
private set; | |
} | |
public T Profile<T>(Func<T> f) | |
{ | |
T result; | |
Calls++; | |
var stopwatch = new System.Diagnostics.Stopwatch(); | |
stopwatch.Start(); | |
result = f(); | |
stopwatch.Stop(); | |
TotalTime += stopwatch.Elapsed; | |
return result; | |
} | |
public void Profile(Action f) | |
{ | |
Calls++; | |
var stopwatch = new System.Diagnostics.Stopwatch(); | |
stopwatch.Start(); | |
f(); | |
stopwatch.Stop(); | |
TotalTime += stopwatch.Elapsed; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment