Skip to content
Snippets Groups Projects
Commit 7d1069bb authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Moved stuff from Timer.cpp to Timer_impl.h

parent b91b9403
No related branches found
No related tags found
1 merge request!22Header only
......@@ -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}
......
......@@ -132,7 +132,6 @@ class Timer
}
};
extern Timer defaultTimer;
} // namespace TNL
#include <TNL/Timer_impl.h>
/***************************************************************************
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 );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment