timer.hxx

Go to the documentation of this file.
00001 // timer.hh: this file is part of the Vaucanson project.
00002 //
00003 // Vaucanson, a generic library for finite state machines.
00004 //
00005 // Copyright (C) 2006, 2007 The Vaucanson Group.
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 // The complete GNU General Public Licence Notice can be found as the
00013 // `COPYING' file in the root directory.
00014 //
00015 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
00016 //
00017 
00023 #ifndef VCSN_MISC_TIMER_HXX
00024 # define VCSN_MISC_TIMER_HXX
00025 
00026 # include <vaucanson/misc/timer.hh>
00027 
00028 NAMESPACE_VCSN_BEGIN
00029 
00030 namespace misc
00031 {
00032 
00033   /*--------.
00034   | Timer.  |
00035   `--------*/
00036 
00037   inline
00038   void
00039   Timer::push (const int i)
00040   {
00041     precondition (intmap.find (i) != intmap.end ());
00042     push (intmap[i]);
00043   }
00044 
00045   inline
00046   void
00047   Timer::pop (const std::string& task_name)
00048   {
00049     precondition (tasksmap[task_name] == *tasks.top ());
00050     pop ();
00051   }
00052 
00053   inline
00054   void
00055   Timer::pop (const int i)
00056   {
00057     pop (intmap[i]);
00058   }
00059 
00060 
00061   inline
00062   void
00063   Timer::print_on_destruction (std::ostream& o)
00064   {
00065     dump_stream = &o;
00066   }
00067 
00068   inline
00069   void
00070   Timer::start ()
00071   {
00072     total.start ();
00073   }
00074 
00075   inline
00076   void
00077   Timer::stop ()
00078   {
00079     total.stop ();
00080   }
00081 
00082   inline
00083   void
00084   Timer::clear ()
00085   {
00086     precondition(tasks.empty ());
00087 
00088     tasksmap.clear ();
00089     intmap.clear ();
00090     total.clear ();
00091     tab_to_disp.clear ();
00092     task_ordered.clear ();
00093   }
00094 
00095   inline
00096   Timer::TimeVar&
00097   Timer::operator[] (const std::string& s)
00098   {
00099     return tasksmap[s];
00100   }
00101 
00102   inline
00103   bool
00104   Timer::operator< (const Timer& rhs) const
00105   {
00106     return total < rhs.total;
00107   }
00108 
00109 
00110   /*--------------.
00111   | Timer::Time.  |
00112   `--------------*/
00113 
00114   inline
00115   Timer::Time::Time ()
00116     : user (0), sys (0), wall (0)
00117   { }
00118 
00119   inline
00120   Timer::Time::operator bool () const
00121   {
00122     return (false
00123             || wall
00124             || user
00125             || sys);
00126   }
00127 
00128   inline
00129   bool
00130   Timer::Time::operator ! () const
00131   {
00132     return (true
00133             && !wall
00134             && !user
00135             && !sys);
00136   }
00137 
00138   inline
00139   Timer::Time&
00140   Timer::Time::operator+= (const Time& lhs)
00141   {
00142     wall += lhs.wall;
00143     user += lhs.user;
00144     sys  += lhs.sys;
00145     return *this;
00146   }
00147 
00148   inline
00149   Timer::Time
00150   Timer::Time::operator+ (const Time& lhs) const
00151   {
00152     Timer::Time res = *this;
00153     return res += lhs;
00154   }
00155 
00156   inline
00157   Timer::Time&
00158   Timer::Time::operator-= (const Time& lhs)
00159   {
00160     wall -= lhs.wall;
00161     user -= lhs.user;
00162     sys  -= lhs.sys;
00163     return *this;
00164   }
00165 
00166   inline
00167   Timer::Time
00168   Timer::Time::operator- (const Time& lhs) const
00169   {
00170     Timer::Time res = *this;
00171     return res -= lhs;
00172   }
00173 
00174   inline
00175   Timer::Time&
00176   Timer::Time::operator/= (unsigned n)
00177   {
00178     wall /= n;
00179     user /= n;
00180     sys  /= n;
00181     return *this;
00182   }
00183 
00184   inline
00185   Timer::Time
00186   Timer::Time::operator/ (unsigned n) const
00187   {
00188     Timer::Time res = *this;
00189     return res /= n;
00190   }
00191 
00192   inline
00193   bool
00194   Timer::Time::operator< (const Timer::Time& rhs) const
00195   {
00196     return (user + sys < rhs.user + rhs.sys
00197             || user < rhs.user
00198             || wall < rhs.wall);
00199   }
00200 
00201 
00202   /*--------------.
00203   | ScopedTimer.  |
00204   `--------------*/
00205 
00206   inline
00207   ScopedTimer::ScopedTimer (Timer& timer, const std::string& key)
00208     : timer_ (timer), key_ (key)
00209   {
00210     timer_.push (key_);
00211   }
00212 
00213   inline
00214   ScopedTimer::~ScopedTimer ()
00215   {
00216     timer_.pop (key_);
00217   }
00218 
00219 } // namespace misc
00220 
00221 NAMESPACE_VCSN_END
00222 
00223 #endif // !VCSN_MISC_TIMER_HXX

Generated on Wed Jun 13 17:00:29 2007 for Vaucanson by  doxygen 1.5.1