port from perforce
This commit is contained in:
44
aiwaz/Aiwaz.Common/HiPerfTimer.cs
Normal file
44
aiwaz/Aiwaz.Common/HiPerfTimer.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Aiwaz.Common
|
||||
{
|
||||
public static class HiPerfTimer
|
||||
{
|
||||
[DllImport("Kernel32.dll")]
|
||||
private static extern bool QueryPerformanceCounter(out long performanceCount);
|
||||
[DllImport("Kernel32.dll")]
|
||||
private static extern bool QueryPerformanceFrequency(out long frequency);
|
||||
private static double? startTime;
|
||||
private static double lastTime;
|
||||
|
||||
public static double LastDeltaTime
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public static double ElapsedTime
|
||||
{
|
||||
get
|
||||
{
|
||||
long frequency, performanceCount;
|
||||
QueryPerformanceFrequency(out frequency);
|
||||
QueryPerformanceCounter(out performanceCount);
|
||||
double thisTime = performanceCount / (double)frequency;
|
||||
if (!startTime.HasValue)
|
||||
{
|
||||
startTime = thisTime;
|
||||
lastTime = thisTime;
|
||||
return 0.0;
|
||||
}
|
||||
LastDeltaTime = thisTime - lastTime;
|
||||
lastTime = thisTime;
|
||||
return thisTime - startTime.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user