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