Skip to content

Instantly share code, notes, and snippets.

@dpogue
Created May 11, 2014 23:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpogue/6dac17c10852653a3103 to your computer and use it in GitHub Desktop.
Save dpogue/6dac17c10852653a3103 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <chrono>
#include <cstdint>
template<typename T = double>
T GetSeconds()
{
typedef std::chrono::high_resolution_clock c;
typedef c::time_point timepoint;
typedef c::duration duration;
typedef std::chrono::duration<T> my_duration;
timepoint tp = c::now();
duration d = tp.time_since_epoch();
return std::chrono::duration_cast<my_duration>(d).count();
}
int main()
{
double secs = GetSeconds();
std::cout << "Seconds (double) = " << secs << std::endl;
uint64_t isecs = GetSeconds<uint64_t>();
std::cout << "Seconds (uint64) = " << isecs << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment