allocator fixes
[csql.git] / include / NanoTimer.h
blobf31dc5f03c0bbc9f9012a66e7df2d6c5713276ba
1 /***************************************************************************
2 * *
3 * Copyright (C) Lakshya Solutions Ltd. All rights reserved. *
4 * *
5 ***************************************************************************/
7 #ifndef NANO_TIMER_H
8 #define NANO_TIMER_H
9 #include<time.h>
10 #include<limits.h>
11 class NanoTimer
13 long long max_, min_, total, count, last_;
14 struct timespec begin;
15 struct timespec end;
17 public:
18 NanoTimer() { reset(); }
19 void reset() { max_ = 0; min_ = LONG_MAX; total =0; count = 0; last_ =0; }
20 void start()
22 count++;
23 clock_gettime(CLOCK_REALTIME, &begin);
25 void stop()
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;
31 total += last_;
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_; }
42 #endif