Revision 80a83cda8db09b459e4ddc7b312f39ea365847e4 authored by RuiZhao on 28 November 2016, 23:37:59 UTC, committed by RuiZhao on 28 November 2016, 23:37:59 UTC
1 parent 9549edd
TimerUtility.cpp
#include "TimerUtility.h"
#include <assert.h>
#ifdef WIN32
#define NOMINMAX
#include "Windows.h"
static LARGE_INTEGER s_ticksPerSecond;
static BOOL s_setFreq = QueryPerformanceFrequency(&s_ticksPerSecond);
#else
#include <time.h>
#endif
namespace Microsoft { namespace MSR { namespace CNTK {
long long Timer::GetStamp()
{
#ifdef WIN32
LARGE_INTEGER li;
QueryPerformanceCounter(&li);
return li.QuadPart;
#else
timespec ts;
clock_gettime(CLOCK_REALTIME, &ts); // Works on Linux
long long ret = ts.tv_sec * NANO_PER_SEC + ts.tv_nsec;
return ret;
#endif
}
void Timer::Start()
{
m_start = GetStamp();
}
void Timer::Restart()
{
m_start = m_end = 0;
Start();
}
void Timer::Stop()
{
m_end = GetStamp();
}
long long Timer::ElapsedMicroseconds()
{
assert(m_start != 0);
long long diff = 0;
if (m_end != 0)
{
diff = m_end - m_start;
}
else
{
diff = GetStamp() - m_start;
}
if (diff < 0)
{
diff = 0;
}
#ifdef WIN32
assert(s_setFreq == TRUE);
return (diff * MICRO_PER_SEC) / s_ticksPerSecond.QuadPart;
#else
return diff / MICRO_PER_NANO;
#endif
}
} } }
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...