Files
OpenRA/OpenRa.Game/Support/Stopwatch.cs
2009-11-17 20:45:30 +13:00

38 lines
754 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace OpenRa.Game.Support
{
class Stopwatch
{
[DllImport("kernel32.dll")]
static extern bool QueryPerformanceCounter(out long value);
[DllImport("kernel32.dll")]
static extern bool QueryPerformanceFrequency(out long frequency);
long freq, start;
public Stopwatch()
{
QueryPerformanceFrequency(out freq);
QueryPerformanceCounter(out start);
}
public double ElapsedTime()
{
long current;
QueryPerformanceCounter(out current);
return (current - start) / (double)freq;
}
public void Reset()
{
QueryPerformanceCounter(out start);
}
}
}