diff --git a/src/TNL/CMakeLists.txt b/src/TNL/CMakeLists.txt index da996f1968b5d824dd1f9af255961c925820fe3d..99362ccf29e48c6451f2f3d6dced9a6d8b2b1225 100644 --- a/src/TNL/CMakeLists.txt +++ b/src/TNL/CMakeLists.txt @@ -35,12 +35,12 @@ set( headers StaticFor.h String.h Timer.h + Timer_impl.h StaticVectorFor.h ) set( common_SOURCES FileName.cpp - String.cpp - Timer.cpp ) + String.cpp ) set( tnl_SOURCES ${tnl_config_SOURCES} ${tnl_containers_SOURCES} diff --git a/src/TNL/Timer.h b/src/TNL/Timer.h index 530dcae216e7241c7ecf4da90854992b366ca7b4..7f2331f185817ba42aa84b3f36e8c0ce9a0dbae5 100644 --- a/src/TNL/Timer.h +++ b/src/TNL/Timer.h @@ -132,7 +132,6 @@ class Timer } }; -extern Timer defaultTimer; - } // namespace TNL +#include <TNL/Timer_impl.h> diff --git a/src/TNL/Timer.cpp b/src/TNL/Timer_impl.h similarity index 80% rename from src/TNL/Timer.cpp rename to src/TNL/Timer_impl.h index e3649367247fcb46cfb084a2990c49cd7623509d..5a1cec336efcb1b226949064a62a9f573eb1ee61 100644 --- a/src/TNL/Timer.cpp +++ b/src/TNL/Timer_impl.h @@ -1,5 +1,5 @@ /*************************************************************************** - Timer.cpp - description + Timer_impl.h - description ------------------- begin : Mar 14, 2016 copyright : (C) 2016 by Tomas Oberhuber @@ -8,6 +8,8 @@ /* See Copyright Notice in tnl/Copyright */ +#pragma once + #include <TNL/Timer.h> #include <TNL/Logger.h> @@ -19,14 +21,12 @@ namespace TNL { -Timer defaultTimer; - -Timer::Timer() +inline Timer::Timer() { reset(); } -void Timer::reset() +inline void Timer::reset() { this->initialCPUTime = 0; this->totalCPUTime = 0.0; @@ -37,7 +37,7 @@ void Timer::reset() this->stopState = true; } -void Timer::stop() +inline void Timer::stop() { if( ! this->stopState ) @@ -49,7 +49,7 @@ void Timer::stop() } } -void Timer::start() +inline void Timer::start() { this->initialRealTime = this->readRealTime(); this->initialCPUTime = this->readCPUTime(); @@ -57,33 +57,33 @@ void Timer::start() this->stopState = false; } -double Timer::getRealTime() const +inline double Timer::getRealTime() const { if( ! this->stopState ) return durationToDouble( this->readRealTime() - this->initialRealTime ); return durationToDouble( this->totalRealTime ); } -double Timer::getCPUTime() const +inline double Timer::getCPUTime() const { if( ! this->stopState ) return this->readCPUTime() - this->initialCPUTime; return this->totalCPUTime; } -unsigned long long int Timer::getCPUCycles() const +inline unsigned long long int Timer::getCPUCycles() const { if( ! this->stopState ) return this->readCPUCycles() - this->initialCPUCycles; return this->totalCPUCycles; } -typename Timer::TimePoint Timer::readRealTime() const +inline typename Timer::TimePoint Timer::readRealTime() const { return std::chrono::high_resolution_clock::now(); } -double Timer::readCPUTime() const +inline double Timer::readCPUTime() const { #if !defined(_WIN32) && !defined(_WIN64) rusage initUsage; @@ -94,19 +94,19 @@ double Timer::readCPUTime() const #endif } -unsigned long long int Timer::readCPUCycles() const +inline unsigned long long int Timer::readCPUCycles() const { return this->rdtsc(); } -double Timer::durationToDouble( const Duration& duration ) const +inline double Timer::durationToDouble( const Duration& duration ) const { std::chrono::duration< double > dur( duration ); return dur.count(); } -bool Timer::writeLog( Logger& logger, int logLevel ) const +inline bool Timer::writeLog( Logger& logger, int logLevel ) const { logger.writeParameter< double >( "Real time:", this->getRealTime(), logLevel ); logger.writeParameter< double >( "CPU time:", this->getCPUTime(), logLevel );