|
// Copyright � 2003 by Jeffrey Sax
// All rights reserved.
// http://www.extremeoptimization.com/
// Filename: timer.cs
// Description: Hi-resolution timer for benchmarking purposes.
// Last modified: April 18, 2003.
using System;
namespace Extreme
{
public class HiResTimer
{
[System.Runtime.InteropServices.DllImport("KERNEL32")]
private static extern bool QueryPerformanceCounter(ref Int64 lpPerformanceCount);
[System.Runtime.InteropServices.DllImport("KERNEL32")]
private static extern bool QueryPerformanceFrequency(ref Int64 lpFrequency);
private Int64 _frequency = 0;
private Int64 _ticksStart = 0;
private Int64 _ticksStop = 0;
public HiResTimer()
{
QueryPerformanceFrequency(ref _frequency);
}
public void Start()
{
_ticksStart = 0;
QueryPerformanceCounter(ref _ticksStart);
}
public void Stop()
{
_ticksStop = 0;
QueryPerformanceCounter(ref _ticksStop);
}
public void Reset()
{
_ticksStart = 0;
_ticksStop = 0;
}
public Single ElapsedSeconds
{
get { return (Single)(_ticksStop - _ticksStart) / (Single)_frequency; }
}
public Single ElapsedMilliSeconds
{
get { return 1000 * ElapsedSeconds; }
}
public Int64 Frequency
{
get { return _frequency; }
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
Jeffrey has been writing numerical software for many years. He is founder and president of
Extreme Optimization, a Toronto based provider of numerical component libraries for the .NET framework. He loves challenges, especially when it comes to making code run fast, and finding simplicity and elegance in what looks like complicated chaos.