PerformanceCounter.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System.Diagnostics;
  2. namespace Ryujinx.Common
  3. {
  4. public static class PerformanceCounter
  5. {
  6. private static double _ticksToNs;
  7. /// <summary>
  8. /// Represents the number of ticks in 1 day.
  9. /// </summary>
  10. public static long TicksPerDay { get; }
  11. /// <summary>
  12. /// Represents the number of ticks in 1 hour.
  13. /// </summary>
  14. public static long TicksPerHour { get; }
  15. /// <summary>
  16. /// Represents the number of ticks in 1 minute.
  17. /// </summary>
  18. public static long TicksPerMinute { get; }
  19. /// <summary>
  20. /// Represents the number of ticks in 1 second.
  21. /// </summary>
  22. public static long TicksPerSecond { get; }
  23. /// <summary>
  24. /// Represents the number of ticks in 1 millisecond.
  25. /// </summary>
  26. public static long TicksPerMillisecond { get; }
  27. /// <summary>
  28. /// Gets the number of ticks elapsed since the system started.
  29. /// </summary>
  30. public static long ElapsedTicks
  31. {
  32. get
  33. {
  34. return Stopwatch.GetTimestamp();
  35. }
  36. }
  37. /// <summary>
  38. /// Gets the number of milliseconds elapsed since the system started.
  39. /// </summary>
  40. public static long ElapsedMilliseconds
  41. {
  42. get
  43. {
  44. long timestamp = Stopwatch.GetTimestamp();
  45. return timestamp / TicksPerMillisecond;
  46. }
  47. }
  48. /// <summary>
  49. /// Gets the number of nanoseconds elapsed since the system started.
  50. /// </summary>
  51. public static long ElapsedNanoseconds
  52. {
  53. get
  54. {
  55. long timestamp = Stopwatch.GetTimestamp();
  56. return (long)(timestamp * _ticksToNs);
  57. }
  58. }
  59. static PerformanceCounter()
  60. {
  61. TicksPerMillisecond = Stopwatch.Frequency / 1000;
  62. TicksPerSecond = Stopwatch.Frequency;
  63. TicksPerMinute = TicksPerSecond * 60;
  64. TicksPerHour = TicksPerMinute * 60;
  65. TicksPerDay = TicksPerHour * 24;
  66. _ticksToNs = 1000000000.0 / Stopwatch.Frequency;
  67. }
  68. }
  69. }