Files
depthsbelow/AStar/HighResolutionTime.cs
T
Simon Holmberg cf100c95f1 3 hours later
2012-09-28 18:59:47 +02:00

46 lines
1.2 KiB
C#
Executable File

using System;
using System.Collections.Generic;
using System.Text;
namespace AStar
{
public static class HighResolutionTime
{
#region Win32APIs
[System.Runtime.InteropServices.DllImport("Kernel32.dll")]
private static extern bool QueryPerformanceCounter(out long perfcount);
[System.Runtime.InteropServices.DllImport("Kernel32.dll")]
private static extern bool QueryPerformanceFrequency(out long freq);
#endregion
#region Variables Declaration
private static long mStartCounter;
private static long mFrequency;
#endregion
#region Constuctors
static HighResolutionTime()
{
QueryPerformanceFrequency(out mFrequency);
}
#endregion
#region Methods
public static void Start()
{
QueryPerformanceCounter(out mStartCounter);
}
public static double GetTime()
{
long endCounter;
QueryPerformanceCounter(out endCounter);
long elapsed = endCounter - mStartCounter;
return (double) elapsed / mFrequency;
}
#endregion
}
}