|
Partner
|
|
|
Kernel Timer für Performancetests
Autor:
Daniel K.
|
Sprache:
C#
|
Bewertung:
7,4 (1 Bewertung)
|
Anzahl der Aufrufe:
5080
|
Beschreibung:
Für genaue Performancetests eignet sich der System.Threading.Timer ggf. nicht, da die TimerEvents nur dann kommen, wenn Windows nix anderes zu tun hat, also bei Idle. Hier eine Möglichkeit den genaueren Timer des Kernels zu verwenden.
Abgelegt unter: Timer, Kernel, Genau, Performance.
|
| C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
using System;
using System.Runtime.InteropServices;
namespace OperationalManagement
{
/// <summary>
/// FxCop Rule CA1060.
/// This type contains members with the DllImport attribute.
/// Members with the DllImport attribute should be contained
/// in classes named NativeMethods, SafeNativeMethods,
/// or UnsafeNativeMethods.
/// </summary>
internal sealed class NativeMethods
{
/// <summary>
/// private Ctor for static Class.
/// </summary>
private NativeMethods()
{
}
/// <summary>
/// DllImport von KERNEL32.
/// </summary>
/// <param name="nPfCt">Performancecounter.</param>
/// <returns>true oder false.</returns>
[DllImport("KERNEL32")]
[return : MarshalAs(UnmanagedType.Bool)]
internal static extern bool QueryPerformanceCounter(ref Int64 nPfCt);
/// <summary>
/// DllImport von KERNEL32.
/// </summary>
/// <param name="nPfFreq">Ferequenz.</param>
/// <returns>true oder false.</returns>
[DllImport("KERNEL32")]
[return : MarshalAs(UnmanagedType.Bool)]
internal static extern bool QueryPerformanceFrequency(ref Int64 nPfFreq);
}
/// <summary>
/// For Performancetestings
/// </summary>
public sealed class KernelTimer
{
private Int64 _i64Frequency;
private Int64 _i64Start;
/// <summary>
/// startet den Timer
/// </summary>
public void Start()
{
Reset();
NativeMethods.QueryPerformanceCounter(ref _i64Start);
}
/// <summary>
/// Zurücksetzen
/// </summary>
public void Reset()
{
NativeMethods.QueryPerformanceFrequency(ref _i64Frequency);
_i64Start = 0;
}
/// <summary>
/// stopt den Timer und liefert das Resultat
/// </summary>
/// <returns>double-Wert.</returns>
public double End()
{
Int64 i64End = 0;
NativeMethods.QueryPerformanceCounter(ref i64End);
return ((i64End - _i64Start)/(double) _i64Frequency);
}
}
}
|
|
Kommentare:
(Zum Schreiben von Kommentaren bitte anmelden.)
|
Stefan Knoll schrieb am:
16.11.2007 10:14:05
|
Daniel K. schrieb am:
03.12.2007 13:27:51
|
|
Diese Snippets könnten für Sie interessant sein:
|
|
|
|
|
|
|
|
|