Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Small little class to time blocks of code.
- // USAGE:
- using (new Benchmark("Some Name For Benchmark"))
- {
- // Code to time
- }
- // SOURCE:
- public class Benchmark : IDisposable
- {
- private readonly string Name;
- private readonly long StartTime;
- private Benchmark() { } // disables default constructor
- public Benchmark(string Name)
- {
- this.Name = Name;
- Console.WriteLine("\n{0} Benchmark Started", Name);
- StartTime = Stopwatch.GetTimestamp();
- }
- public void Dispose()
- {
- long StopTime = Stopwatch.GetTimestamp();
- Console.WriteLine("\n{0} Benchmark Finished : {1}s", Name, (decimal)(StopTime - StartTime) / Stopwatch.Frequency);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement