Skip to content

Instantly share code, notes, and snippets.

@KayEss
Last active September 10, 2020 13:20
Show Gist options
  • Save KayEss/fdb3dc2fe997cb0b449c190e198f5982 to your computer and use it in GitHub Desktop.
Save KayEss/fdb3dc2fe997cb0b449c190e198f5982 to your computer and use it in GitHub Desktop.
Quick clock
// clang++ -O3 time.cpp -o ttt
#include <chrono>
#include <iostream>
int main() {
auto last = std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::system_clock::now().time_since_epoch()).count();
while(true) {
auto const now = std::chrono::system_clock::now();
auto const ns = std::chrono::duration_cast<std::chrono::nanoseconds>(
now.time_since_epoch()).count();
std::cout << (ns / std::nano::den) << '.' << (ns % std::nano::den)
<< " -- " << (ns - last) << " \r" << std::flush;
last = ns;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment