-
-
Save toshok/47e993196048a8261026 to your computer and use it in GitHub Desktop.
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
#include <stdio.h> | |
#include <chrono> | |
#include <x86intrin.h> | |
#include <unistd.h> | |
struct rdtsc_clock { | |
typedef unsigned long long rep; | |
typedef std::ratio<1, 2800098000> period; // /proc/cpuinfo says 2800.098 for cpu MHz | |
typedef std::chrono::duration<rep, period> duration; | |
typedef std::chrono::time_point<rdtsc_clock> time_point; | |
static const bool is_steady = true; | |
static time_point now() noexcept | |
{ | |
return time_point(duration(static_cast<rep>(__rdtsc()))); | |
} | |
}; | |
int | |
main() | |
{ | |
rdtsc_clock::time_point start = rdtsc_clock::now(); | |
sleep(10); | |
rdtsc_clock::time_point end = rdtsc_clock::now(); | |
printf ("%ld ms\n", std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment