wall_clock_meat.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2009 NICTA
00002 // 
00003 // Authors:
00004 // - Conrad Sanderson (conradsand at ieee dot org)
00005 // 
00006 // This file is part of the Armadillo C++ library.
00007 // It is provided without any warranty of fitness
00008 // for any purpose. You can redistribute this file
00009 // and/or modify it under the terms of the GNU
00010 // Lesser General Public License (LGPL) as published
00011 // by the Free Software Foundation, either version 3
00012 // of the License or (at your option) any later version.
00013 // (see http://www.opensource.org/licenses for more info)
00014 
00015 
00016 //! \addtogroup wall_clock
00017 //! @{
00018 
00019 
00020 inline
00021 wall_clock::wall_clock()
00022   : valid(false)
00023   {
00024   arma_extra_debug_sigprint();
00025   }
00026 
00027 
00028 
00029 inline
00030 wall_clock::~wall_clock()
00031   {
00032   arma_extra_debug_sigprint();
00033   }
00034 
00035 
00036 
00037 inline
00038 void
00039 wall_clock::tic()
00040   {
00041   arma_extra_debug_sigprint();
00042   
00043   #if defined(ARMA_USE_BOOST)
00044     {
00045     boost_time1 = boost::posix_time::microsec_clock::local_time();
00046     }
00047   #else
00048     {
00049     gettimeofday(&posix_time1, 0);
00050     }
00051   #endif
00052   
00053   valid = true;
00054   }
00055 
00056 
00057 
00058 inline
00059 double
00060 wall_clock::toc()
00061   {
00062   arma_extra_debug_sigprint();
00063   
00064   if(valid)
00065     {
00066     #if defined(ARMA_USE_BOOST)
00067       {
00068       boost_duration = boost::posix_time::microsec_clock::local_time() - boost_time1;
00069       return boost_duration.total_microseconds() * 1e-6;
00070       }
00071     #else
00072       {
00073       gettimeofday(&posix_time2, 0);
00074       
00075       const double tmp_time1 = posix_time1.tv_sec + posix_time1.tv_usec * 1.0e-6;
00076       const double tmp_time2 = posix_time2.tv_sec + posix_time2.tv_usec * 1.0e-6;
00077       
00078       return tmp_time2 - tmp_time1;
00079       }
00080     #endif
00081     }
00082   else
00083     {  
00084     return 0.0;
00085     }
00086   }
00087 
00088 //! @}
00089