PerfTimer.cs 1006 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Threading;
  5. namespace System.Data.Linq.SqlClient {
  6. #if PERFORMANCE_BUILD
  7. class PerfTimer {
  8. long startTime;
  9. long stopTime;
  10. long frequency;
  11. public PerfTimer() {
  12. QueryPerformanceFrequency(out frequency);
  13. }
  14. public void Start() {
  15. Thread.Sleep(0);
  16. QueryPerformanceCounter(out startTime);
  17. }
  18. public void Stop() {
  19. QueryPerformanceCounter(out stopTime);
  20. }
  21. public long Duration {
  22. get { return (long)( 1000000.0 * (double)(stopTime - startTime) / (double) frequency ); }
  23. }
  24. [System.Runtime.InteropServices.DllImport("Kernel32.dll")]
  25. private static extern bool QueryPerformanceCounter(out long count);
  26. [System.Runtime.InteropServices.DllImport("Kernel32.dll")]
  27. private static extern bool QueryPerformanceFrequency(out long frequency);
  28. }
  29. #endif
  30. }