diff options
| author | Baruch Burstein | 2017-07-09 12:48:29 +0300 |
|---|---|---|
| committer | Baruch Burstein | 2017-07-09 12:48:29 +0300 |
| commit | af05ccfe5d9096e203f63e5cde07e6767f532334 (patch) | |
| tree | de302ee0ef9b1cb671ad81e4a19716e37f6e6f2b /include/internal/catch_timer.cpp | |
| parent | 058b21e604dd3486fe4f7957e4a4485104943905 (diff) | |
| parent | fc32165d48f0a46a60ac02e0e52f8c89adafd8be (diff) | |
| download | catch3-af05ccfe5d9096e203f63e5cde07e6767f532334.tar.gz | |
Merge remote-tracking branch 'upstream/dev-modernize' into dev-better-verbosity
Diffstat (limited to 'include/internal/catch_timer.cpp')
| -rw-r--r-- | include/internal/catch_timer.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/include/internal/catch_timer.cpp b/include/internal/catch_timer.cpp new file mode 100644 index 00000000..d4066fa9 --- /dev/null +++ b/include/internal/catch_timer.cpp @@ -0,0 +1,34 @@ +/* + * 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" + +#include <chrono> + +namespace Catch { + + namespace { + uint64_t getCurrentMicrosecondsSinceEpoch() { + return std::chrono::duration_cast<std::chrono::microseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count(); + } + } + + void Timer::start() { + m_microSeconds = getCurrentMicrosecondsSinceEpoch(); + } + unsigned int Timer::getElapsedMicroseconds() const { + return static_cast<unsigned int>(getCurrentMicrosecondsSinceEpoch() - m_microSeconds); + } + unsigned int Timer::getElapsedMilliseconds() const { + return static_cast<unsigned int>(getElapsedMicroseconds()/1000); + } + double Timer::getElapsedSeconds() const { + return getElapsedMicroseconds()/1000000.0; + } + +} // namespace Catch |