00001 // -*- C++ -*- 00002 /* 00003 Phrasehunter - index and query text corpora 00004 Copyright (C) 2006 Torsten Marek (shlomme@gmx.de) & 00005 Armin Schmidt (armin.sch@gmail.com) 00006 00007 This program is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU General Public License 00009 as published by the Free Software Foundation; either version 2 00010 of the License, or (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #ifndef HPTIMER_HPP 00023 #define HPTIMER_HPP HPTIMER_HPP 00024 00025 #include <sys/timeb.h> 00026 00027 //! Class to be used for timing in perfomance evaluation. 00028 class hptimer 00029 { 00030 public: 00031 //! Constructor. Initialize timing. 00032 hptimer() 00033 { restart(); } 00034 //! Restart this timer. 00035 void restart() { _start_time = get_time(); } 00036 //! Returns the time elapsed since initialization or last restart(). 00037 unsigned long elapsed() const 00038 { return get_time() - _start_time; } 00039 00040 private: 00041 unsigned long get_time() const 00042 { 00043 timeb current_time; 00044 ftime(¤t_time); 00045 return static_cast<unsigned long>(current_time.time) * 1000 + current_time.millitm; 00046 } 00047 00048 unsigned long _start_time; 00049 }; // hptimer 00050 00051 #endif // HPTIMER_HPP