การจับเวลาด้วย Python

ตัวอย่างการใช้ฟังก์ชั่น clock() and time() บน Windows and Linux
Run on linux
  >>> from time import clock, time
  >>> print clock(), time()
  0.01 1169573460.96
  >>> print clock(), time()
  0.01 1169573463.76
  >>> print clock(), time()
  0.01 1169573467.09
  >>> 
Run on Windows
  >>> from time import clock, time
  >>> print clock(), time()
  7.54285810068e-006 1169574534.84
  >>> print clock(), time()
  3.32073322168 1169574538.16
  >>> print clock(), time()
  7.32428004118 1169574542.15
  >>>  #!/usr/bin/python

จะเห็นได้ว่าฟังก์ชั่น time() เหมาะกับการนำมาใช้จับเวลามากกว่า (แต่ก็ไม่ตรงซะทีเดียว สู้คำสั่ง command line:time  ไม่ได้)
import time

def procedure():
    time.sleep(2.5)

# measure process time
t0 = time.clock()
procedure()
print time.clock() - t0, "seconds process time"

# measure wall time
t0 = time.time()
procedure()
print time.time() - t0, "seconds wall time"

0.0 seconds process time
2.50023603439 seconds wall time

ที่มา: stackoverflow.com, docs.python.org, tutorialspoint.com