From 7d1069bb2c54b6c8e313dbfab2da2d35db297778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= <klinkjak@fjfi.cvut.cz> Date: Sat, 17 Nov 2018 14:24:35 +0100 Subject: [PATCH] Moved stuff from Timer.cpp to Timer_impl.h --- src/TNL/CMakeLists.txt | 4 ++-- src/TNL/Timer.h | 3 +-- src/TNL/{Timer.cpp => Timer_impl.h} | 30 ++++++++++++++--------------- 3 files changed, 18 insertions(+), 19 deletions(-) rename src/TNL/{Timer.cpp => Timer_impl.h} (80%) diff --git a/src/TNL/CMakeLists.txt b/src/TNL/CMakeLists.txt index da996f1968..99362ccf29 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 530dcae216..7f2331f185 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 e364936724..5a1cec336e 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 ); -- GitLab