author | moel.mich |
Sat, 07 Sep 2013 08:07:11 +0000 | |
changeset 423 | 47f5dcaf8e9f |
permissions | -rw-r--r-- |
moel@345 | 1 |
using System; |
moel@345 | 2 |
using System.Collections.Generic; |
moel@345 | 3 |
using System.Text; |
moel@345 | 4 |
using System.Runtime.InteropServices; |
moel@345 | 5 |
using System.Diagnostics.CodeAnalysis; |
moel@345 | 6 |
|
moel@345 | 7 |
namespace Aga.Controls |
moel@345 | 8 |
{ |
moel@345 | 9 |
/// <summary> |
moel@345 | 10 |
/// High resolution timer, used to test performance |
moel@345 | 11 |
/// </summary> |
moel@345 | 12 |
public static class TimeCounter |
moel@345 | 13 |
{ |
moel@345 | 14 |
private static Int64 _start; |
moel@345 | 15 |
|
moel@345 | 16 |
/// <summary> |
moel@345 | 17 |
/// Start time counting |
moel@345 | 18 |
/// </summary> |
moel@345 | 19 |
public static void Start() |
moel@345 | 20 |
{ |
moel@345 | 21 |
_start = 0; |
moel@345 | 22 |
QueryPerformanceCounter(ref _start); |
moel@345 | 23 |
} |
moel@345 | 24 |
|
moel@345 | 25 |
public static Int64 GetStartValue() |
moel@345 | 26 |
{ |
moel@345 | 27 |
Int64 t = 0; |
moel@345 | 28 |
QueryPerformanceCounter(ref t); |
moel@345 | 29 |
return t; |
moel@345 | 30 |
} |
moel@345 | 31 |
|
moel@345 | 32 |
/// <summary> |
moel@345 | 33 |
/// Finish time counting |
moel@345 | 34 |
/// </summary> |
moel@345 | 35 |
/// <returns>time in seconds elapsed from Start till Finish </returns> |
moel@345 | 36 |
public static double Finish() |
moel@345 | 37 |
{ |
moel@345 | 38 |
return Finish(_start); |
moel@345 | 39 |
} |
moel@345 | 40 |
|
moel@345 | 41 |
public static double Finish(Int64 start) |
moel@345 | 42 |
{ |
moel@345 | 43 |
Int64 finish = 0; |
moel@345 | 44 |
QueryPerformanceCounter(ref finish); |
moel@345 | 45 |
|
moel@345 | 46 |
Int64 freq = 0; |
moel@345 | 47 |
QueryPerformanceFrequency(ref freq); |
moel@345 | 48 |
return (finish - start) / (double)freq; |
moel@345 | 49 |
} |
moel@345 | 50 |
|
moel@345 | 51 |
[DllImport("Kernel32.dll")] |
moel@345 | 52 |
[return: MarshalAs(UnmanagedType.Bool)] |
moel@345 | 53 |
static extern bool QueryPerformanceCounter(ref Int64 performanceCount); |
moel@345 | 54 |
|
moel@345 | 55 |
[DllImport("Kernel32.dll")] |
moel@345 | 56 |
[return: MarshalAs(UnmanagedType.Bool)] |
moel@345 | 57 |
static extern bool QueryPerformanceFrequency(ref Int64 frequency); |
moel@345 | 58 |
} |
moel@345 | 59 |
} |