Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changeset 2172

Show
Ignore:
Timestamp:
05/07/07 04:10:37 (5 years ago)
Author:
kris
Message:

attempt to resolve accuracy issues

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tango/util/time/StopWatch.d

    r2167 r2172  
    6565public struct StopWatch 
    6666{ 
    67         private Interval        started; 
     67        private ulong  started; 
    6868        private static Interval multiplier = 1.0 / 1_000_000.0; 
    69  
    70         version (Win32) 
    71                  private static ulong timerStart; 
    7269 
    7370        /*********************************************************************** 
     
    9087        Interval stop () 
    9188        { 
    92                 return timer - started
     89                return multiplier * (timer - started)
    9390        } 
    9491 
     
    105102                        ulong freq; 
    106103 
    107                         if (! QueryPerformanceFrequency (&freq)) 
    108                               throw new Exception ("high-resolution timer is not available"); 
    109                          
    110                         QueryPerformanceCounter (&timerStart); 
     104                        QueryPerformanceFrequency (&freq); 
    111105                        multiplier = 1.0 / freq;        
    112106                } 
     
    119113        ***********************************************************************/ 
    120114 
    121         private static Interval timer () 
     115        private static ulong timer () 
    122116        { 
    123117                version (Posix)        
     
    127121                            throw new Exception ("Timer :: linux timer is not available"); 
    128122 
    129                         return (cast(Interval) tv.tv_sec) + tv.tv_usec * multiplier
     123                        return (cast(ulong) tv.tv_sec * 1_000_000) + tv.tv_usec
    130124                } 
    131125 
     
    134128                        ulong now; 
    135129 
    136                         QueryPerformanceCounter (&now); 
    137                         return (now - timerStart) * multiplier; 
     130                        if (! QueryPerformanceCounter (&now)) 
     131                              throw new Exception ("high-resolution timer is not available"); 
     132 
     133                        return now; 
    138134                } 
    139135        } 
     
    154150                t.start; 
    155151 
    156                 for (int i=0; i < 10_000_000; ++i) 
     152                for (int i=0; i < 100_000_000; ++i) 
    157153                    {} 
    158154                Stdout.format ("{:f9}", t.stop).newline;