Created
April 24, 2013 08:23
-
-
Save pinscript/5450569 to your computer and use it in GitHub Desktop.
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.Diagnostics; | |
| namespace Stemmer | |
| { | |
| internal class Benchmark : IDisposable | |
| { | |
| private readonly string _name; | |
| private Stopwatch _stopwatch; | |
| public Benchmark(string name) | |
| { | |
| _name = name; | |
| _stopwatch = new Stopwatch(); | |
| _stopwatch.Start(); | |
| } | |
| public void Dispose() | |
| { | |
| _stopwatch.Stop(); | |
| Console.Write("- "); | |
| Console.ForegroundColor = ConsoleColor.Red; | |
| Console.Write("{0}", _name); | |
| Console.ResetColor(); | |
| Console.Write(" took "); | |
| Console.ForegroundColor = ConsoleColor.Green; | |
| Console.Write("{0}", _stopwatch.ElapsedMilliseconds); | |
| Console.ResetColor(); | |
| Console.WriteLine("ms"); | |
| _stopwatch = null; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment