moel@345: using System;
moel@345: using System.Collections.Generic;
moel@345: using System.Text;
moel@345: using System.Runtime.InteropServices;
moel@345: using System.Diagnostics.CodeAnalysis;
moel@345:
moel@345: namespace Aga.Controls
moel@345: {
moel@345: ///
moel@345: /// High resolution timer, used to test performance
moel@345: ///
moel@345: public static class TimeCounter
moel@345: {
moel@345: private static Int64 _start;
moel@345:
moel@345: ///
moel@345: /// Start time counting
moel@345: ///
moel@345: public static void Start()
moel@345: {
moel@345: _start = 0;
moel@345: QueryPerformanceCounter(ref _start);
moel@345: }
moel@345:
moel@345: public static Int64 GetStartValue()
moel@345: {
moel@345: Int64 t = 0;
moel@345: QueryPerformanceCounter(ref t);
moel@345: return t;
moel@345: }
moel@345:
moel@345: ///
moel@345: /// Finish time counting
moel@345: ///
moel@345: /// time in seconds elapsed from Start till Finish
moel@345: public static double Finish()
moel@345: {
moel@345: return Finish(_start);
moel@345: }
moel@345:
moel@345: public static double Finish(Int64 start)
moel@345: {
moel@345: Int64 finish = 0;
moel@345: QueryPerformanceCounter(ref finish);
moel@345:
moel@345: Int64 freq = 0;
moel@345: QueryPerformanceFrequency(ref freq);
moel@345: return (finish - start) / (double)freq;
moel@345: }
moel@345:
moel@345: [DllImport("Kernel32.dll")]
moel@345: [return: MarshalAs(UnmanagedType.Bool)]
moel@345: static extern bool QueryPerformanceCounter(ref Int64 performanceCount);
moel@345:
moel@345: [DllImport("Kernel32.dll")]
moel@345: [return: MarshalAs(UnmanagedType.Bool)]
moel@345: static extern bool QueryPerformanceFrequency(ref Int64 frequency);
moel@345: }
moel@345: }