1 /***************************************************************************
3 * Copyright (C) Lakshya Solutions Ltd. All rights reserved. *
5 ***************************************************************************/
11 class DllExport NanoTimer
13 long long max_
, min_
, total
, count
, last_
;
15 unsigned __int64 begin
, end
;
17 struct timespec begin
;
21 NanoTimer() { reset(); }
22 void reset() { max_
= 0; min_
= LONG_MAX
; total
=0; count
= 0; last_
=0; }
29 GetSystemTimeAsFileTime(&ft
);
30 // The GetSystemTimeAsFileTime returns the number of 100 nanosecond
31 // intervals since Jan 1, 1601 in a structure. Copy the high bits to
32 // the 64 bit tmpres, shift it left by 32 then or in the low 32 bits.
33 begin
|= ft
.dwHighDateTime
;
35 begin
|= ft
.dwLowDateTime
;
37 clock_gettime(CLOCK_REALTIME
, &begin
);
45 GetSystemTimeAsFileTime(&ft
);
46 // The GetSystemTimeAsFileTime returns the number of 100 nanosecond
47 // intervals since Jan 1, 1601 in a structure. Copy the high bits to
48 // the 64 bit tmpres, shift it left by 32 then or in the low 32 bits.
49 end
|= ft
.dwHighDateTime
;
51 end
|= ft
.dwLowDateTime
;
54 clock_gettime(CLOCK_REALTIME
, &end
);
55 long long secs
= end
.tv_sec
-begin
.tv_sec
;
56 long long nano
= end
.tv_nsec
-begin
.tv_nsec
;
57 last_
= (secs
*1000000000)+nano
;
60 if ( max_
< last_
) max_
= last_
;
61 if ( min_
> last_
) min_
= last_
;
63 long long last() { return last_
; }
64 long long avg() { return total
/count
; }
65 long long sum() { return total
; }
66 long long minc() { return min_
; }
67 long long maxc() { return max_
; }