1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/External/Aga.Controls/TimeCounter.cs Sun May 27 15:16:19 2012 +0000
1.3 @@ -0,0 +1,59 @@
1.4 +using System;
1.5 +using System.Collections.Generic;
1.6 +using System.Text;
1.7 +using System.Runtime.InteropServices;
1.8 +using System.Diagnostics.CodeAnalysis;
1.9 +
1.10 +namespace Aga.Controls
1.11 +{
1.12 + /// <summary>
1.13 + /// High resolution timer, used to test performance
1.14 + /// </summary>
1.15 + public static class TimeCounter
1.16 + {
1.17 + private static Int64 _start;
1.18 +
1.19 + /// <summary>
1.20 + /// Start time counting
1.21 + /// </summary>
1.22 + public static void Start()
1.23 + {
1.24 + _start = 0;
1.25 + QueryPerformanceCounter(ref _start);
1.26 + }
1.27 +
1.28 + public static Int64 GetStartValue()
1.29 + {
1.30 + Int64 t = 0;
1.31 + QueryPerformanceCounter(ref t);
1.32 + return t;
1.33 + }
1.34 +
1.35 + /// <summary>
1.36 + /// Finish time counting
1.37 + /// </summary>
1.38 + /// <returns>time in seconds elapsed from Start till Finish </returns>
1.39 + public static double Finish()
1.40 + {
1.41 + return Finish(_start);
1.42 + }
1.43 +
1.44 + public static double Finish(Int64 start)
1.45 + {
1.46 + Int64 finish = 0;
1.47 + QueryPerformanceCounter(ref finish);
1.48 +
1.49 + Int64 freq = 0;
1.50 + QueryPerformanceFrequency(ref freq);
1.51 + return (finish - start) / (double)freq;
1.52 + }
1.53 +
1.54 + [DllImport("Kernel32.dll")]
1.55 + [return: MarshalAs(UnmanagedType.Bool)]
1.56 + static extern bool QueryPerformanceCounter(ref Int64 performanceCount);
1.57 +
1.58 + [DllImport("Kernel32.dll")]
1.59 + [return: MarshalAs(UnmanagedType.Bool)]
1.60 + static extern bool QueryPerformanceFrequency(ref Int64 frequency);
1.61 + }
1.62 +}