Last active
October 16, 2025 12:39
-
-
Save savanovich/f07eda9dba9300eb9ccf to your computer and use it in GitHub Desktop.
Using RDTSC instruction that returns CPU TSC (Time Stamp Counter)
This file contains hidden or 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
| /* 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); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot for this. U just saved my life