2013-08-07 19:56:35 +02:00
|
|
|
/*
|
|
|
|
* Created by Phil on 05/08/2013.
|
|
|
|
* Copyright 2013 Two Blue Cubes Ltd. All rights reserved.
|
|
|
|
*
|
|
|
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "catch_timer.h"
|
2013-08-16 20:08:39 +02:00
|
|
|
#include "catch_platform.h"
|
2013-08-07 19:56:35 +02:00
|
|
|
|
2013-08-16 20:08:39 +02:00
|
|
|
#ifdef CATCH_PLATFORM_WINDOWS
|
2017-02-21 12:32:32 +01:00
|
|
|
|
|
|
|
# include "catch_windows_h_proxy.h"
|
|
|
|
|
2013-08-07 19:56:35 +02:00
|
|
|
#else
|
2017-02-21 12:32:32 +01:00
|
|
|
|
2013-08-07 19:56:35 +02:00
|
|
|
#include <sys/time.h>
|
2017-03-01 16:58:57 +01:00
|
|
|
|
2013-08-07 19:56:35 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace Catch {
|
|
|
|
|
|
|
|
namespace {
|
2013-08-16 20:08:39 +02:00
|
|
|
#ifdef CATCH_PLATFORM_WINDOWS
|
2013-08-07 19:56:35 +02:00
|
|
|
uint64_t getCurrentTicks() {
|
|
|
|
static uint64_t hz=0, hzo=0;
|
|
|
|
if (!hz) {
|
2015-03-04 20:00:29 +01:00
|
|
|
QueryPerformanceFrequency( reinterpret_cast<LARGE_INTEGER*>( &hz ) );
|
|
|
|
QueryPerformanceCounter( reinterpret_cast<LARGE_INTEGER*>( &hzo ) );
|
2013-08-07 19:56:35 +02:00
|
|
|
}
|
|
|
|
uint64_t t;
|
2015-03-04 20:00:29 +01:00
|
|
|
QueryPerformanceCounter( reinterpret_cast<LARGE_INTEGER*>( &t ) );
|
2013-08-07 19:56:35 +02:00
|
|
|
return ((t-hzo)*1000000)/hz;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
uint64_t getCurrentTicks() {
|
|
|
|
timeval t;
|
2017-04-25 12:41:30 +02:00
|
|
|
gettimeofday(&t,nullptr);
|
2014-07-09 08:35:34 +02:00
|
|
|
return static_cast<uint64_t>( t.tv_sec ) * 1000000ull + static_cast<uint64_t>( t.tv_usec );
|
2013-08-07 19:56:35 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void Timer::start() {
|
|
|
|
m_ticks = getCurrentTicks();
|
|
|
|
}
|
2014-09-03 20:20:23 +02:00
|
|
|
unsigned int Timer::getElapsedMicroseconds() const {
|
2014-07-09 08:35:34 +02:00
|
|
|
return static_cast<unsigned int>(getCurrentTicks() - m_ticks);
|
2013-08-07 19:56:35 +02:00
|
|
|
}
|
|
|
|
unsigned int Timer::getElapsedMilliseconds() const {
|
2014-09-03 20:20:23 +02:00
|
|
|
return static_cast<unsigned int>(getElapsedMicroseconds()/1000);
|
2013-08-07 19:56:35 +02:00
|
|
|
}
|
|
|
|
double Timer::getElapsedSeconds() const {
|
2014-09-03 20:20:23 +02:00
|
|
|
return getElapsedMicroseconds()/1000000.0;
|
2013-08-07 19:56:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Catch
|