2016-01-14 18:45:04 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StopWatch.h"
|
|
|
|
|
|
|
|
#if defined(_WIN32) || defined(_WIN64)
|
|
|
|
|
|
|
|
CStopWatch::CStopWatch() :
|
|
|
|
m_frequency(),
|
|
|
|
m_start()
|
|
|
|
{
|
|
|
|
::QueryPerformanceFrequency(&m_frequency);
|
|
|
|
}
|
|
|
|
|
|
|
|
CStopWatch::~CStopWatch()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long CStopWatch::start()
|
|
|
|
{
|
|
|
|
::QueryPerformanceCounter(&m_start);
|
|
|
|
|
|
|
|
return (unsigned long)(m_start.QuadPart / m_frequency.QuadPart);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int CStopWatch::elapsed()
|
|
|
|
{
|
|
|
|
LARGE_INTEGER now;
|
|
|
|
::QueryPerformanceCounter(&now);
|
|
|
|
|
|
|
|
LARGE_INTEGER temp;
|
|
|
|
temp.QuadPart = (now.QuadPart - m_start.QuadPart) * 1000;
|
|
|
|
|
|
|
|
return (unsigned int)(temp.QuadPart / m_frequency.QuadPart);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2016-01-25 23:10:40 +00:00
|
|
|
#include <cstdio>
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
CStopWatch::CStopWatch() :
|
|
|
|
m_start()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CStopWatch::~CStopWatch()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long CStopWatch::start()
|
|
|
|
{
|
2016-01-24 21:18:53 +00:00
|
|
|
::gettimeofday(&m_start, NULL);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2016-01-24 21:18:53 +00:00
|
|
|
return m_start.tv_usec;
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int CStopWatch::elapsed()
|
|
|
|
{
|
2016-01-24 21:18:53 +00:00
|
|
|
struct timeval now;
|
|
|
|
::gettimeofday(&now, NULL);
|
|
|
|
|
2016-01-25 18:10:51 +00:00
|
|
|
unsigned int elapsed = (now.tv_sec - m_start.tv_sec) * 1000U;
|
|
|
|
elapsed += now.tv_usec / 1000U;
|
|
|
|
elapsed -= m_start.tv_usec / 1000U;
|
2016-01-24 21:18:53 +00:00
|
|
|
|
2016-01-26 07:13:55 +00:00
|
|
|
return elapsed;
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|