fork download
  1. import time
  2.  
  3. # Set your CPU frequency in Hz (e.g., 3.0 GHz CPU is 3_000_000_000 cycles per second)
  4. CPU_FREQUENCY_HZ = 3_000_000_000 # 3 GHz
  5.  
  6. # Number of iterations for the loop
  7. loop_count = 1000000
  8.  
  9. # Start time in seconds (high-resolution timestamp)
  10. start_time = time.perf_counter()
  11.  
  12. # Execute the loop
  13. for _ in range(loop_count):
  14. pass # No-operation equivalent
  15.  
  16. # End time in seconds
  17. end_time = time.perf_counter()
  18.  
  19. # Calculate the elapsed time in seconds
  20. elapsed_time = end_time - start_time
  21.  
  22. # Convert elapsed time to CPU cycles
  23. elapsed_cycles = int(elapsed_time * CPU_FREQUENCY_HZ)
  24.  
  25. # Display the result
  26. print(f"Time taken: {elapsed_cycles} cycles")
  27.  
Success #stdin #stdout 0.1s 9656KB
stdin
Standard input is empty
stdout
Time taken: 185371343 cycles