time.clock not functioning - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: time.clock not functioning (/thread-33203.html) |
time.clock not functioning - Oldman45 - Apr-06-2021 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: 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: Please can anyone shed light on why time.clock is not recognised? Thank you.
RE: time.clock not functioning - perfringo - Apr-06-2021 time.clock() is deprecated since Python 3.3 RE: time.clock not functioning - ibreeden - Apr-06-2021 Always look at the official documentation in such cases: The Python Standard Library. Try time.time() instead. RE: time.clock not functioning - Oldman45 - Apr-07-2021 Thanks perfringo and ibreeden, very helpful |