Advertisement
Guest User

Difference between time.time() and time.clock()

a guest
Aug 11th, 2013
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. def fac(a):
  2.     if a <= 1: return 1
  3.     return a * fac(a-1)
  4.  
  5. def a(n):
  6.     import time
  7.     t = time.time()
  8.     c = time.clock()
  9.     for i in range(200, 900):
  10.         f = fac(i)
  11.         s = "Thread %d: %d -> (X)" % (n, i,) # fac(i))
  12.         s += "@ t:%f c:%f" % (time.time() - t, time.clock() - c)
  13.         print s
  14.  
  15. if 1:
  16.     import os
  17.     #Fork bomb alarm: 3 leads to 8 processes!
  18.     #for i in range(3): os.fork()
  19.     pids = [os.fork() for i in range(3)]
  20.     print pids
  21.     import time
  22.     time.sleep(.7)
  23.     # now the show begins:
  24.     a(os.getpid())
  25. else:
  26.     import threading
  27.     threads = [threading.Thread(target=a, args=(i,)) for i in range(10)]
  28.     for t in threads: t.start()
  29.     for t in threads: t.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement