https://github.com/Microsoft/CNTK
Revision 218d2da137c9ba38d2ae272e0a557d74c5408d6a authored by jeanfad on 06 June 2016, 14:34:12 UTC, committed by jeanfad on 28 June 2016, 09:24:30 UTC
1 parent 3c01d90
Raw File
Tip revision: 218d2da137c9ba38d2ae272e0a557d74c5408d6a authored by jeanfad on 06 June 2016, 14:34:12 UTC
little docstring fixes
Tip revision: 218d2da
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
}
} } }
back to top