max@0: // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) max@0: // Copyright (C) 2008-2012 Conrad Sanderson max@0: // max@0: // This file is part of the Armadillo C++ library. max@0: // It is provided without any warranty of fitness max@0: // for any purpose. You can redistribute this file max@0: // and/or modify it under the terms of the GNU max@0: // Lesser General Public License (LGPL) as published max@0: // by the Free Software Foundation, either version 3 max@0: // of the License or (at your option) any later version. max@0: // (see http://www.opensource.org/licenses for more info) max@0: max@0: max@0: //! \addtogroup wall_clock max@0: //! @{ max@0: max@0: max@0: inline max@0: wall_clock::wall_clock() max@0: : valid(false) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: max@0: max@0: inline max@0: wall_clock::~wall_clock() max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: max@0: max@0: inline max@0: void max@0: wall_clock::tic() max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: #if defined(ARMA_USE_BOOST_DATE) max@0: { max@0: boost_time1 = boost::posix_time::microsec_clock::local_time(); max@0: valid = true; max@0: } max@0: #elif defined(ARMA_HAVE_GETTIMEOFDAY) max@0: { max@0: gettimeofday(&posix_time1, 0); max@0: valid = true; max@0: } max@0: #else max@0: { max@0: time1 = clock(); max@0: valid = true; max@0: } max@0: #endif max@0: } max@0: max@0: max@0: max@0: inline max@0: double max@0: wall_clock::toc() max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: if(valid) max@0: { max@0: #if defined(ARMA_USE_BOOST_DATE) max@0: { max@0: boost_duration = boost::posix_time::microsec_clock::local_time() - boost_time1; max@0: return boost_duration.total_microseconds() * 1e-6; max@0: } max@0: #elif defined(ARMA_HAVE_GETTIMEOFDAY) max@0: { max@0: gettimeofday(&posix_time2, 0); max@0: max@0: const double tmp_time1 = posix_time1.tv_sec + posix_time1.tv_usec * 1.0e-6; max@0: const double tmp_time2 = posix_time2.tv_sec + posix_time2.tv_usec * 1.0e-6; max@0: max@0: return tmp_time2 - tmp_time1; max@0: } max@0: #else max@0: { max@0: clock_t time2 = clock(); max@0: max@0: clock_t diff = time2 - time1; max@0: max@0: return double(diff) / double(CLOCKS_PER_SEC); max@0: } max@0: #endif max@0: } max@0: else max@0: { max@0: return 0.0; max@0: } max@0: } max@0: max@0: max@0: max@0: //! @} max@0: