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
|
|
|
|
|
|
|
#ifdef __clang__
|
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Wc++11-long-long"
|
|
|
|
#endif
|
|
|
|
|
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
|
2017-04-25 16:15:59 +02:00
|
|
|
UInt64 getCurrentTicks() {
|
|
|
|
static UInt64 hz=0, hzo=0;
|
2013-08-07 19:56:35 +02:00
|
|
|
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
|
|
|
}
|
2017-04-25 16:15:59 +02:00
|
|
|
UInt64 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
|
2017-04-25 16:15:59 +02:00
|
|
|
UInt64 getCurrentTicks() {
|
2013-08-07 19:56:35 +02:00
|
|
|
timeval t;
|
2015-07-01 08:33:27 +02:00
|
|
|
gettimeofday(&t,CATCH_NULL);
|
2017-04-25 16:15:59 +02:00
|
|
|
return static_cast<UInt64>( t.tv_sec ) * 1000000ull + static_cast<UInt64>( 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
|
|
|
|
|
|
|
|
#ifdef __clang__
|
|
|
|
#pragma clang diagnostic pop
|
|
|
|
#endif
|