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


Messages In This Thread
time.clock not functioning - by Oldman45 - Apr-06-2021, 10:33 AM
RE: time.clock not functioning - by perfringo - Apr-06-2021, 11:00 AM
RE: time.clock not functioning - by ibreeden - Apr-06-2021, 11:35 AM
RE: time.clock not functioning - by Oldman45 - Apr-07-2021, 08:51 AM

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