Advertisement
TizzyT

Benchmark -TizzyT

May 22nd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. // Small little class to time blocks of code.
  2. // USAGE:
  3.     using (new Benchmark("Some Name For Benchmark"))
  4.     {
  5.         // Code to time
  6.     }
  7.  
  8. // SOURCE:
  9.     public class Benchmark : IDisposable
  10.     {
  11.         private readonly string Name;
  12.         private readonly long StartTime;
  13.  
  14.         private Benchmark() { } // disables default constructor
  15.         public Benchmark(string Name)
  16.         {
  17.             this.Name = Name;
  18.             Console.WriteLine("\n{0} Benchmark Started", Name);
  19.             StartTime = Stopwatch.GetTimestamp();
  20.         }
  21.  
  22.         public void Dispose()
  23.         {
  24.             long StopTime = Stopwatch.GetTimestamp();
  25.             Console.WriteLine("\n{0} Benchmark Finished : {1}s", Name, (decimal)(StopTime - StartTime) / Stopwatch.Frequency);
  26.         }
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement