1 /***************************************************************************
3 * Copyright (C) Lakshya Solutions Ltd. All rights reserved. *
5 ***************************************************************************/
13 long long max_
, min_
, total
, count
, last_
;
14 struct timespec begin
;
18 NanoTimer() { reset(); }
19 void reset() { max_
= 0; min_
= LONG_MAX
; total
=0; count
= 0; last_
=0; }
23 clock_gettime(CLOCK_REALTIME
, &begin
);
27 clock_gettime(CLOCK_REALTIME
, &end
);
28 long long secs
= end
.tv_sec
-begin
.tv_sec
;
29 long long nano
= end
.tv_nsec
-begin
.tv_nsec
;
30 last_
= (secs
*1000000000)+nano
;
32 if ( max_
< last_
) max_
= last_
;
33 if ( min_
> last_
) min_
= last_
;
35 long long last() { return last_
; }
36 long long avg() { return total
/count
; }
37 long long sum() { return total
; }
38 long long min() { return min_
; }
39 long long max() { return max_
; }