Skip to content

Instantly share code, notes, and snippets.

@savanovich
Last active October 16, 2025 12:39
Show Gist options
  • Select an option

  • Save savanovich/f07eda9dba9300eb9ccf to your computer and use it in GitHub Desktop.

Select an option

Save savanovich/f07eda9dba9300eb9ccf to your computer and use it in GitHub Desktop.
Using RDTSC instruction that returns CPU TSC (Time Stamp Counter)
/* https://ru.wikipedia.org/wiki/Rdtsc */
#include <stdio.h>
typedef unsigned long long uint64;
int main() {
uint64 val;
unsigned int h, l;
for (int i=0; i<=10; i++) {
__asm__ __volatile__("rdtsc" : "=a" (l), "=d" (h));
val = ((uint64)l) | (((uint64)h) << 32);
printf("%llu \n", val);
}
}
@antonio20028
Copy link

Thanks a lot for this. U just saved my life

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment