BWAPI
|
00001 // Copyright (c) 1997 Utrecht University (The Netherlands), 00002 // ETH Zurich (Switzerland), Freie Universitaet Berlin (Germany), 00003 // INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg 00004 // (Germany), Max-Planck-Institute Saarbruecken (Germany), RISC Linz (Austria), 00005 // and Tel-Aviv University (Israel). All rights reserved. 00006 // 00007 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or 00008 // modify it under the terms of the GNU Lesser General Public License as 00009 // published by the Free Software Foundation; version 2.1 of the License. 00010 // See the file LICENSE.LGPL distributed with CGAL. 00011 // 00012 // Licensees holding a valid commercial license may use this file in 00013 // accordance with the commercial license agreement provided with the software. 00014 // 00015 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00016 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00017 // 00018 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Profiling_tools/include/CGAL/Real_timer.h $ 00019 // $Id: Real_timer.h 41685 2008-01-18 20:19:17Z spion $ 00020 // 00021 // 00022 // Author(s) : Lutz Kettner <kettner@inf.ethz.ch> 00023 // Matthias Baesken <baesken@informatik.uni-halle.de> 00024 00025 #ifndef CGAL_REAL_TIMER_H 00026 #define CGAL_REAL_TIMER_H 1 00027 00028 #include <CGAL/basic.h> 00029 // For the numerical limits 00030 #include <cfloat> 00031 00032 CGAL_BEGIN_NAMESPACE 00033 00034 // SECTION: A Timer Measuring Real-Time 00035 // ======================================================================== 00036 // 00037 // DEFINITION 00038 // 00039 // A timer `t' of type Real_timer is an object with a state. It is either 00040 // running or it is stopped. The state is controlled with `t.start()' 00041 // and `t.stop()'. The timer counts the time elapsed since its creation 00042 // or last reset. It counts only the time where it is in the running 00043 // state. The time information is given in seconds. 00044 00045 class Real_timer { 00046 private: 00047 double elapsed; 00048 double started; 00049 int interv; 00050 bool running; 00051 00052 static bool m_failed; 00053 00054 double get_real_time() const; // in seconds 00055 double compute_precision() const; // in seconds 00056 public: 00057 Real_timer() : elapsed(0.0), started(0.0), interv(0), running(false) {} 00058 00059 void start(); 00060 void stop (); 00061 void reset(); 00062 bool is_running() const { return running; } 00063 00064 double time() const; 00065 int intervals() const { return interv; } 00066 double precision() const; 00067 // Returns timer precison. Computes it dynamically at first call. 00068 // Returns -1.0 if timer system call fails, which, for a proper coded 00069 // test towards precision leads to an immediate stop of an otherwise 00070 // infinite loop (fixed tolerance * total time >= precision). 00071 double max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return DBL_MAX; } 00072 }; 00073 00074 00075 // ----------------------------------------------------------------------- 00076 00077 // Member functions for Real_timer 00078 // =========================== 00079 00080 inline void Real_timer::start() { 00081 CGAL_precondition( ! running); 00082 started = get_real_time(); 00083 running = true; 00084 ++ interv; 00085 } 00086 00087 inline void Real_timer::stop() { 00088 CGAL_precondition( running); 00089 double t = get_real_time(); 00090 elapsed += (t - started); 00091 started = 0.0; 00092 running = false; 00093 } 00094 00095 inline void Real_timer::reset() { 00096 interv = 0; 00097 elapsed = 0.0; 00098 if (running) { 00099 started = get_real_time(); 00100 ++ interv; 00101 } else { 00102 started = 0.0; 00103 } 00104 } 00105 00106 inline double Real_timer::time() const { 00107 if (running) { 00108 double t = get_real_time(); 00109 return elapsed + (t - started); 00110 } 00111 return elapsed; 00112 } 00113 00114 CGAL_END_NAMESPACE 00115 00116 #endif // CGAL_REAL_TIMER_H // 00117 // EOF //