Skip to content

Instantly share code, notes, and snippets.

@rbcmgs
Last active May 1, 2024 18:08
Show Gist options
  • Select an option

  • Save rbcmgs/29611016567adfe55650ef3438251d8c to your computer and use it in GitHub Desktop.

Select an option

Save rbcmgs/29611016567adfe55650ef3438251d8c to your computer and use it in GitHub Desktop.
A Python script to measure the time it takes to enumerate and print numbers from 0 to 10,000. Useful for comparing enumeration speeds across different Python versions.
#!/usr/bin/env python3
import timeit
def enumeration():
""" Enumerates numbers from 0 to 10,000 and prints each number. """
for i in range(10001):
print(i)
# Time the execution of the enumeration function over 10 iterations.
execution_time = timeit.timeit(enumeration, number=10)
# Output the average execution time per iteration.
print(f"Average execution time: {execution_time/10:.6f} seconds")
# Instructions:
# - Ensure Python is correctly installed on your system.
# - To test this script with different Python versions, run the script with a command using the target version:
# `python3.6 enum_speed_test.py`
# `python3.7 enum_speed_test.py`
# - Replace `python3.6` or `python3.7` with the desired Python version installed on your system.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment