00001 /** @file rutz/stopwatch.h track elapsed wall-clock time */ 00002 00003 /////////////////////////////////////////////////////////////////////// 00004 // 00005 // Copyright (c) 1999-2004 California Institute of Technology 00006 // Copyright (c) 2004-2007 University of Southern California 00007 // Rob Peters <rjpeters at usc dot edu> 00008 // 00009 // created: Thu Nov 18 10:24:59 1999 00010 // commit: $Id: stopwatch.h 8249 2007-04-12 06:03:40Z rjpeters $ 00011 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/rutz/stopwatch.h $ 00012 // 00013 // -------------------------------------------------------------------- 00014 // 00015 // This file is part of GroovX. 00016 // [http://ilab.usc.edu/rjpeters/groovx/] 00017 // 00018 // GroovX is free software; you can redistribute it and/or modify it 00019 // under the terms of the GNU General Public License as published by 00020 // the Free Software Foundation; either version 2 of the License, or 00021 // (at your option) any later version. 00022 // 00023 // GroovX is distributed in the hope that it will be useful, but 00024 // WITHOUT ANY WARRANTY; without even the implied warranty of 00025 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00026 // General Public License for more details. 00027 // 00028 // You should have received a copy of the GNU General Public License 00029 // along with GroovX; if not, write to the Free Software Foundation, 00030 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 00031 // 00032 /////////////////////////////////////////////////////////////////////// 00033 00034 #ifndef GROOVX_RUTZ_STOPWATCH_H_UTC20050626084019_DEFINED 00035 #define GROOVX_RUTZ_STOPWATCH_H_UTC20050626084019_DEFINED 00036 00037 #include "rutz/time.h" 00038 00039 namespace rutz 00040 { 00041 class stopwatch; 00042 } 00043 00044 /// Tracks elapsed wall-clock time. 00045 class rutz::stopwatch 00046 { 00047 public: 00048 /// Default constructor. 00049 stopwatch() : m_start_time() { restart(); } 00050 00051 /// Reset the start time to the current time. 00052 void restart() 00053 { m_start_time = rutz::time::wall_clock_now(); } 00054 00055 /// Get the time elapsed between start and stop times. 00056 rutz::time elapsed(const rutz::time& stop) const 00057 { 00058 return stop - m_start_time; 00059 } 00060 00061 /// Get the time elapsed between start and now. 00062 rutz::time elapsed() const 00063 { 00064 return elapsed(rutz::time::wall_clock_now()); 00065 } 00066 00067 private: 00068 rutz::time m_start_time; 00069 }; 00070 00071 static const char __attribute__((used)) vcid_groovx_rutz_stopwatch_h_utc20050626084019[] = "$Id: stopwatch.h 8249 2007-04-12 06:03:40Z rjpeters $ $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/rutz/stopwatch.h $"; 00072 #endif // !GROOVX_RUTZ_STOPWATCH_H_UTC20050626084019_DEFINED