Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include/internal/catch_timer.cpp
diff options
context:
space:
mode:
authorMartin Hořeňovský2017-07-06 22:28:42 +0200
committerMartin Hořeňovský2017-07-06 22:28:42 +0200
commitfc32165d48f0a46a60ac02e0e52f8c89adafd8be (patch)
treeacf2c6dc020615db581ce425b7ce0a424d801f83 /include/internal/catch_timer.cpp
parent0016362f69804ae18953a0ec11d0c108e8402e1d (diff)
downloadcatch3-fc32165d48f0a46a60ac02e0e52f8c89adafd8be.tar.gz
Started work on splitting out .cpp files from header files
Diffstat (limited to 'include/internal/catch_timer.cpp')
-rw-r--r--include/internal/catch_timer.cpp34
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