using System.Diagnostics; namespace AIDiagnosisDemo.GC { internal class CpuClock { #region Fields and Events  // Fields  private static double _cpuFrequency; private double _startTime; #endregion Fields and Events  #region Methods  // Constructors  public CpuClock() { _startTime = GetCurrentTimestamp(); } static CpuClock() { long counter; counter = Stopwatch.Frequency; _cpuFrequency = counter; } // Methods  private static long QueryPerformanceCounter() { long counter; counter = Stopwatch.GetTimestamp(); return counter; } private static long QueryPerformanceFrequency() { long cpuFrequency; cpuFrequency = Stopwatch.Frequency; return cpuFrequency; } private static double GetCurrentTimestamp() { long newCounter = QueryPerformanceCounter(); return newCounter / (double)_cpuFrequency; } /// /// Returns the spent time(as second) after the CpuClock is created /// /// public double GetTime() { return TotalSeconds; } /// /// Returns the spent time(as second) after system start /// /// public static double Current { get { return GetCurrentTimestamp(); } } public double StartTime { get { return _startTime; } } public double TotalSeconds { get { return (Current - _startTime); } } public double TotalMilliSeconds { get { return (Current - _startTime) * 1000; } } public static CpuClock Now { get { return new CpuClock(); } } #endregion Methods  } }