fork download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #ifdef _MSC_VER
  4. #include <intrin.h> // For Windows (MSVC compiler)
  5. #else
  6. #include <x86intrin.h> // For GCC/Clang on x86 platforms
  7. #endif
  8.  
  9. int main() {
  10. uint64_t start_time, end_time, time_diff;
  11. int i, loop_count = 1000000;
  12.  
  13. // Get start time (in CPU cycles)
  14. start_time = __rdtsc();
  15.  
  16. // Loop to measure
  17. for (i = 0; i < loop_count; i++) {
  18. __asm__ __volatile__("nop"); // No-operation to simulate work
  19. }
  20.  
  21. // Get end time (in CPU cycles)
  22. end_time = __rdtsc();
  23.  
  24. // Calculate time difference
  25. time_diff = end_time - start_time;
  26.  
  27. // Print the time taken in CPU cycles
  28. printf("Time taken: %llu cycles\n", time_diff);
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
Time taken: 946936 cycles