Skip to content

Instantly share code, notes, and snippets.

@pinscript
Created April 24, 2013 08:23
Show Gist options
  • Select an option

  • Save pinscript/5450569 to your computer and use it in GitHub Desktop.

Select an option

Save pinscript/5450569 to your computer and use it in GitHub Desktop.
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