diff options
author | Paolo Molaro <lupus@oddwiz.org> | 2008-02-26 19:51:52 +0300 |
---|---|---|
committer | Paolo Molaro <lupus@oddwiz.org> | 2008-02-26 19:51:52 +0300 |
commit | 40c299e777fc8d642ccaf55c4b352f6738d69d39 (patch) | |
tree | b0eedc0e6801535f877fc5f67d427ef050fdd7df /mcs/class/System/System.Diagnostics/Stopwatch.cs | |
parent | c4a75e5a4803f8fe89f9a9fba57d6ca3745a32e0 (diff) |
Tue Feb 26 18:37:13 CET 2008 Paolo Molaro <lupus@ximian.com>
* Stopwatch.cs: use an hires monotonic clock.
svn path=/trunk/mcs/; revision=96667
Diffstat (limited to 'mcs/class/System/System.Diagnostics/Stopwatch.cs')
-rw-r--r-- | mcs/class/System/System.Diagnostics/Stopwatch.cs | 44 |
1 files changed, 10 insertions, 34 deletions
diff --git a/mcs/class/System/System.Diagnostics/Stopwatch.cs b/mcs/class/System/System.Diagnostics/Stopwatch.cs index 1cb2bef2e50..1f038be7d6c 100644 --- a/mcs/class/System/System.Diagnostics/Stopwatch.cs +++ b/mcs/class/System/System.Diagnostics/Stopwatch.cs @@ -32,33 +32,20 @@ #if NET_2_0 using System; -using System.ComponentModel;
+using System.ComponentModel; using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; namespace System.Diagnostics { public class Stopwatch - {
- [DllImport ("kernel32.dll")]
- static extern bool QueryPerformanceCounter (out long performance_count);
-
- [DllImport ("kernel32.dll")]
- static extern bool QueryPerformanceFrequency (out long frequency); - - public static readonly long Frequency; - - public static readonly bool IsHighResolution; - - public static long GetTimestamp () - {
- if (IsHighResolution) {
- long performance_count;
- QueryPerformanceCounter (out performance_count);
- return performance_count; - } - else - return DateTime.Now.Ticks; - } + { + [MethodImplAttribute(MethodImplOptions.InternalCall)] + internal static extern long GetTimestamp (); + + public static readonly long Frequency = 10000000; + + public static readonly bool IsHighResolution = true; public static Stopwatch StartNew () { @@ -67,20 +54,9 @@ namespace System.Diagnostics return s; } - static Stopwatch () - {
- Frequency = TimeSpan.TicksPerSecond;
- IsHighResolution = false;
- int platform = (int) Environment.OSVersion.Platform; - if ((platform != 4) && (platform != 128)) {
- // try to use high performance timer on Windows.
- IsHighResolution = QueryPerformanceFrequency (out Frequency); - } - } - public Stopwatch () { - }
+ } long elapsed; long started; |