-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature #1983: Made CmiWallTimer monotonic in the common case
Reimplemented one of CmiWallTimer's commonly used code branches to use the highest resolution steady clock from C++11 instead of gettimeofday. The new implementation also stores the epoch in an integral time_point, and uses the starting time of the program as the epoch to reduce the internal floating-point error. Change-Id: I4ad82339bda69b9a17ba408ed824d1dea36cdf74
- Loading branch information
1 parent
f5c7833
commit 73d9771
Showing
5 changed files
with
51 additions
and
21 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
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,27 @@ | ||
#include <chrono> | ||
#include <type_traits> | ||
#include "hrctimer.h" | ||
#include <ratio> | ||
|
||
using clock_type=typename std::conditional< | ||
std::chrono::high_resolution_clock::is_steady, | ||
std::chrono::high_resolution_clock, | ||
std::chrono::steady_clock>::type; | ||
static std::chrono::time_point<clock_type> epoch; | ||
|
||
double inithrc() { //defines our HRC epoch | ||
epoch = clock_type::now(); | ||
return std::chrono::duration<double>(epoch.time_since_epoch()).count(); | ||
} | ||
double gethrctime() { | ||
auto timepoint = clock_type::now(); //gets HRC timepoint | ||
auto time_since_epoch = timepoint-epoch; //gets the elapsed time since the start of HRC clock | ||
double seconds = std::chrono::duration<double>(time_since_epoch).count(); //converts that time into seconds(double) | ||
return seconds; | ||
} | ||
uint64_t gethrctime_micro() { | ||
auto timepoint = clock_type::now(); //gets HRC timepoint | ||
auto time_since_epoch = timepoint-epoch; //gets the elapsed time since the start of HRC clock | ||
auto microseconds = std::chrono::duration_cast<std::chrono::microseconds>(time_since_epoch).count(); //converts that time into microseconds(integer) | ||
return microseconds; | ||
} |
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,13 @@ | ||
#ifndef HRCTIMER_H | ||
#define HRCTIMER_H | ||
#include <inttypes.h> | ||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
double inithrc(); | ||
double gethrctime(); | ||
uint64_t gethrctime_micro(); | ||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif |
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
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