How to measure the range() function time in Python

2 Answers

0 votes
import time

start = time.perf_counter()
for x in range(10000000):
    pass
stop = time.perf_counter()
 
print(stop - start, "seconds")
 
 
'''
run:
 
0.49576009700012946 seconds
 
'''

 



answered Oct 15, 2017 by avibootz
edited Aug 4, 2024 by avibootz
0 votes
import time

start = time.perf_counter()
for x in range(10000):
    pass
stop = time.perf_counter()
 
print(stop - start, "seconds")
 
 
'''
run:
 
0.0005147800000031566 seconds
 
'''

 



answered Oct 15, 2017 by avibootz
edited Aug 4, 2024 by avibootz
...