Created
November 29, 2013 05:14
-
-
Save gyuwon/7701850 to your computer and use it in GitHub Desktop.
Simple .NET performance measurement helper class
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
/** | |
* 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