Apr-06-2021, 10:33 AM
I am using the following coding, from a text book, to compare two methods of measuring execution time for coding but time.clock is not recognised. I am on Windows 10 using Python 3.9.2
The coding is:
The coding is:
import time def do_my_sum(xs): sum = 0 for v in xs: sum += v return sz = 10000000 #10000000 elements in the list testdata = range(sz) t0 = time.clock() my_result = do_my_sum(testdata) t1 = time.clock() print("my_result = {0} {time taken = {1:4f} seconds) " ,format(their_result, t1 - t0)) t2 = time.clock() their_result = sum(testdata) t3 = time.clock() print("their_result = {0} (time taken = {1: .4f} seconds) " .format(their_result, t3 - t2))And the output is:
Output:Traceback (most recent call last):
File "C:\Users\qm31\Desktop\testing.py", line 12, in <module>
t0 = time.clock()
AttributeError: module 'time' has no attribute 'clock'
Please can anyone shed light on why time.clock is not recognised? Thank you.