using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.ComponentModel;
namespace HiPerfTimer
{
public class HiPerfTimer
{
[DllImport("Kernel32.dll")]
private static extern bool QueryPerformanceCounter(out long lpPerformanceCount);
[DllImport("Kernel32.dll")]
private static extern bool QueryPerformanceFrequency(out long lpFrequency);
public HiPerfTimer()
{
this.startTime = 0;
this.stopTime = 0;
if (QueryPerformanceFrequency(out this.freq) == false)
{
throw new Win32Exception();
}
}
public void Start()
{
System.Threading.Thread.Sleep(0);
QueryPerformanceCounter(out this.startTime);
}
public void Stop()
{
QueryPerformanceCounter(out this.stopTime);
}
public double Duration
{
get
{
return (double)(this.stopTime - this.startTime) / (double)this.freq;
}
}
public void Clear()
{
this.startTime = 0;
this.stopTime = 0;
}
private long startTime;
private long stopTime;
private long freq;
}
}