00001 #include <chrono>
00002 #include <type_traits>
00003 #include "hrctimer.h"
00004 #include <ratio>
00005
00006 using clock_type=typename std::conditional<
00007 std::chrono::high_resolution_clock::is_steady,
00008 std::chrono::high_resolution_clock,
00009 std::chrono::steady_clock>::type;
00010 static std::chrono::time_point<clock_type> epoch;
00011
00012 double inithrc() {
00013 epoch = clock_type::now();
00014 return std::chrono::duration<double>(epoch.time_since_epoch()).count();
00015 }
00016 double gethrctime() {
00017 auto timepoint = clock_type::now();
00018 auto time_since_epoch = timepoint-epoch;
00019 double seconds = std::chrono::duration<double>(time_since_epoch).count();
00020 return seconds;
00021 }
00022 uint64_t gethrctime_micro() {
00023 auto timepoint = clock_type::now();
00024 auto time_since_epoch = timepoint-epoch;
00025 auto microseconds = std::chrono::duration_cast<std::chrono::microseconds>(time_since_epoch).count();
00026 return microseconds;
00027 }