Skip to content

Instantly share code, notes, and snippets.

@gyuwon
Created November 29, 2013 05:14
Show Gist options
  • Save gyuwon/7701850 to your computer and use it in GitHub Desktop.
Save gyuwon/7701850 to your computer and use it in GitHub Desktop.
Simple .NET performance measurement helper class
/**
* using (Job.StartNew("JobName"))
* {
* // Execution
* }
*/
class Job : System.IDisposable
{
public static Job StartNew(string name)
{
return new Job(name);
}
private string _name;
private System.Diagnostics.Stopwatch _stopwatch;
private Job(string name)
{
this._name = name;
this._stopwatch = System.Diagnostics.Stopwatch.StartNew();
System.Console.WriteLine("[{0} started]", this._name);
}
public void Dispose()
{
this._stopwatch.Stop();
System.Console.WriteLine("[{0} finished] {1}ms elapsed", this._name, this._stopwatch.ElapsedMilliseconds);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment