0
0
Fork 0
This repository has been archived on 2024-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
ryujinx-final/Ryujinx.Common/PerformanceCounter.cs
jduncanator c1b7340023 Timing: Optimize Timestamp Aquisition (#479)
* Timing: Optimize Timestamp Aquisition

Currently, we make use of Environment.TickCount in a number of places. This has some downsides, mainly being that the TickCount is a signed 32-bit integer, and has an effective limit of ~25 days before overflowing and wrapping around. Due to the signed-ness of the value, this also caused issues with negative numbers. This resolves these issues by using a 64-bit tick count obtained from Performance Counters (via the Stopwatch class). This has a beneficial side effect of being significantly more accurate than the TickCount.

* Timing: Rename ElapsedTicks to ElapsedMilliseconds and expose TicksPerX

* Timing: Some style changes

* Timing: Align static variable initialization
2018-10-28 19:31:13 -03:00

65 lines
1.8 KiB
C#

using System.Diagnostics;
namespace Ryujinx.Common
{
public static class PerformanceCounter
{
/// <summary>
/// Represents the number of ticks in 1 day.
/// </summary>
public static long TicksPerDay { get; }
/// <summary>
/// Represents the number of ticks in 1 hour.
/// </summary>
public static long TicksPerHour { get; }
/// <summary>
/// Represents the number of ticks in 1 minute.
/// </summary>
public static long TicksPerMinute { get; }
/// <summary>
/// Represents the number of ticks in 1 second.
/// </summary>
public static long TicksPerSecond { get; }
/// <summary>
/// Represents the number of ticks in 1 millisecond.
/// </summary>
public static long TicksPerMillisecond { get; }
/// <summary>
/// Gets the number of milliseconds elapsed since the system started.
/// </summary>
public static long ElapsedTicks
{
get
{
return Stopwatch.GetTimestamp();
}
}
/// <summary>
/// Gets the number of milliseconds elapsed since the system started.
/// </summary>
public static long ElapsedMilliseconds
{
get
{
long timestamp = Stopwatch.GetTimestamp();
return timestamp / TicksPerMillisecond;
}
}
static PerformanceCounter()
{
TicksPerMillisecond = Stopwatch.Frequency / 1000;
TicksPerSecond = Stopwatch.Frequency;
TicksPerMinute = TicksPerSecond * 60;
TicksPerHour = TicksPerMinute * 60;
TicksPerDay = TicksPerHour * 24;
}
}
}