include/NanoTimer.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 by www.databasecache.com                           *
00003  *   Contact: praba_tuty@databasecache.com                                 *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015   ***************************************************************************/
00016 #ifndef NANO_TIMER_H
00017 #define NANO_TIMER_H
00018 #include<time.h>
00019 #include<limits.h>
00020 class NanoTimer 
00021 {
00022     long long max_, min_, total, count, last_;
00023     struct timespec begin;
00024     struct timespec end;
00025 
00026     public:
00027     NanoTimer() {  reset(); }
00028     void reset() {  max_ = 0; min_ = LONG_MAX; total =0; count = 0; last_ =0; }
00029     void start()
00030     {
00031         count++;
00032         clock_gettime(CLOCK_REALTIME, &begin);
00033     }
00034     void stop()
00035     {
00036         clock_gettime(CLOCK_REALTIME, &end);
00037         long long secs = end.tv_sec-begin.tv_sec;
00038         long long nano = end.tv_nsec-begin.tv_nsec;
00039         last_ = (secs*1000000000)+nano;
00040         total += last_;
00041         if ( max_ < last_ ) max_ = last_;
00042         if ( min_ > last_ ) min_ = last_;
00043     }
00044     long long last() { return last_; }
00045     long long avg() { return total/count; }
00046     long long min() { return min_; }
00047     long long max() { return max_; }
00048 };
00049 
00050 #endif

Generated on Mon Jun 9 22:37:14 2008 for csql by  doxygen 1.4.7