Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #593 from leapmotion/feature-chrono-ext
Added basic_timer.h and chrono_types.h
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (C) 2012-2015 Leap Motion, Inc. All rights reserved. | ||
#pragma once | ||
#include <chrono> | ||
|
||
template<class clock_t, class duration_t = typename clock_t::duration> | ||
class basic_timer { | ||
public: | ||
basic_timer(const typename clock_t::time_point& initial = clock_t::now()) : m_start(initial) {} | ||
|
||
//A convenient method to avoid having to use duration_cast all the time. | ||
duration_t now() const { return std::chrono::duration_cast<duration_t>(clock_t::now().time_since_epoch()); } | ||
duration_t elapsed() const { return std::chrono::duration_cast<duration_t>(clock_t::now() - m_start); } | ||
typename clock_t::time_point start_time() const { return m_start; } | ||
|
||
void start() { m_start = clock_t::now(); } | ||
duration_t mark() { | ||
const auto now = clock_t::now(); | ||
const auto oldStart = m_start; | ||
m_start = now; | ||
return std::chrono::duration_cast<duration_t>(now - oldStart); | ||
} | ||
private: | ||
typename clock_t::time_point m_start; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (C) 2012-2015 Leap Motion, Inc. All rights reserved. | ||
#pragma once | ||
#include <autowiring/C++11/cpp11.h> | ||
#include CHRONO_HEADER | ||
#include "chrono_timer.h" | ||
|
||
//Common chrono types | ||
typedef std::chrono::duration<double> seconds_d; | ||
typedef std::chrono::duration<double, std::milli> milliseconds_d; | ||
typedef std::chrono::duration<double, std::micro> microseconds_d; | ||
typedef std::chrono::duration<double, std::nano> nanoseconds_d; | ||
|
||
typedef std::chrono::duration<float> seconds_f; | ||
typedef std::chrono::duration<float, std::milli> milliseconds_f; | ||
typedef std::chrono::duration<float, std::micro> microseconds_f; | ||
typedef std::chrono::duration<float, std::nano> nanoseconds_f; | ||
|
||
typedef basic_timer<std::chrono::profiling_clock> profiling_timer; | ||
typedef basic_timer<std::chrono::profiling_clock, seconds_d> profiling_timer_seconds; | ||
typedef basic_timer<std::chrono::profiling_clock, milliseconds_d> profiling_timer_milliseconds; | ||
typedef basic_timer<std::chrono::profiling_clock, microseconds_d> profiling_timer_microseconds; |