Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
time.clock not functioning
#1
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:
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.
Reply
#2
time.clock() is deprecated since Python 3.3
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
Always look at the official documentation in such cases: The Python Standard Library.
Try time.time() instead.
Reply
#4
Thanks perfringo and ibreeden, very helpful
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Module 'time' has no attribute 'clock' Sophie 4 3,031 Jan-25-2022, 08:05 PM
Last Post: Sophie
  Clock\time calculation script Drone4four 3 1,441 Jan-21-2022, 03:44 PM
Last Post: ibreeden
  I can`t find an IDE functioning in my laptop All_ex_Under 5 2,922 Aug-17-2020, 05:44 AM
Last Post: All_ex_Under
  If elif else statement not functioning SamDiggityDog 4 2,599 Jun-03-2020, 12:27 AM
Last Post: SamDiggityDog
  Cannot use function with timer/clock theangryprogrammer 1 3,288 Jan-22-2019, 04:22 PM
Last Post: Larz60+
  Data manipulation code running but not functioning correctly homotextual 1 2,128 Dec-30-2018, 03:19 PM
Last Post: ichabod801
  Pythonista script with iPhone's native Clock app Sharkman157 0 2,576 Sep-27-2018, 05:23 PM
Last Post: Sharkman157
  Python shell not functioning Kongurinn 2 3,345 Oct-19-2017, 10:03 PM
Last Post: Kongurinn
  Problem with 'Clock' functionality panoss 2 3,534 May-17-2017, 07:03 PM
Last Post: snippsat
  How to talk with Real Time Clock hardware? jackbk 12 11,134 Feb-15-2017, 05:53 AM
Last Post: jackbk

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020