time_meter.hpp

00001 /*
00002 
00003 Copyright (c) 2002-2005, Yauheni Akhotnikau
00004 All rights reserved.
00005 
00006 Redistribution and use in source and binary forms, with or without
00007 modification, are permitted provided that the following conditions are met:
00008 
00009 - Redistributions of source code must retain the above copyright notice, this
00010 list of conditions and the following disclaimer.
00011 
00012 - Redistributions in binary form must reproduce the above copyright notice, this
00013 list of conditions and the following disclaimer in the documentation and/or
00014 other materials provided with the distribution.
00015 
00016 - The name of the author may not be used to endorse or promote products derived
00017 from this software without specific prior written permission.
00018 
00019 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
00020 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00021 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
00022 EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00024 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00027 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
00028 OF SUCH DAMAGE.
00029 
00030 */
00031 
00032 #if !defined( _TIME_METER_HPP_ )
00033 #define _TIME_METER_HPP_
00034 
00035 #include <string>
00036 #include <ctime>
00037 
00038 namespace oess_1
00039 {
00040 
00041 namespace debug
00042 {
00043 
00044 class time_accumulator_t
00045   {
00046   private :
00047     std::string m_name;
00048     double  m_value;
00049     double  m_max_delta;
00050     unsigned int  m_count;
00051 
00052   public :
00053     inline time_accumulator_t(
00054       const std::string & name )
00055       : m_name( name )
00056       , m_value( 0 )
00057       , m_max_delta( 0 )
00058       , m_count( 0 )
00059       {}
00060 
00061     inline ~time_accumulator_t()
00062       {
00063         std::cout << m_name << ": " << m_value
00064           << " (max: " << std::fixed << m_max_delta
00065           << ", avg: " << std::fixed << ( m_count ? m_value / m_count : 0.0 )
00066           << ", cnt: " << m_count << ")" << std::endl;
00067       }
00068 
00069     inline void
00070     operator+=( double delta )
00071       {
00072         if( delta < 0.00000001 )
00073           delta = 0.00000001;
00074 
00075         m_value += delta;
00076         ++m_count;
00077         if( m_max_delta < delta )
00078           m_max_delta = delta;
00079       }
00080   };
00081 
00082 class time_meter_t
00083   {
00084   private :
00085     time_accumulator_t &  m_accumulator;
00086     std::clock_t  m_start;
00087 
00088   public :
00089     inline time_meter_t(
00090       time_accumulator_t & accumulator )
00091       : m_accumulator( accumulator )
00092       , m_start( std::clock() )
00093       {}
00094 
00095     inline ~time_meter_t()
00096       {
00097         std::clock_t finish = std::clock();
00098         m_accumulator += double( finish - m_start ) / CLOCKS_PER_SEC;
00099       }
00100   };
00101 
00102 } /* namespace debug */
00103 
00104 } /* namespace oess_1 */
00105 
00106 #endif

Документация по ObjESSty. Последние изменения: Fri Oct 13 18:35:36 2006. Создано системой  doxygen 1.4.7
Hosted by uCoz