Advertisement
here2share

# tuple_ctypes_clockit.py

Dec 2nd, 2019
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. # tuple_ctypes_timeit.py
  2.  
  3. from multiprocessing import Process, Lock
  4. from multiprocessing.sharedctypes import Value, Array
  5. from ctypes import Structure, c_double
  6. from random import randint
  7. from time import clock as ttt
  8.  
  9. t = 100000
  10. def rXY():
  11.     return (randint(0,800), randint(0,1280))
  12. L = [rXY() for z in range(t)]
  13.  
  14. class Point(Structure):
  15.     _fields_ = [('x', c_double), ('y', c_double)]
  16.  
  17. def ct(A):
  18.     for a in A:
  19.         a.x = 2
  20.         a.y = 4
  21.  
  22. def py(B):
  23.     for b in range(len(B)):
  24.         B[b] = 3,6
  25.  
  26. if __name__ == '__main__':
  27.  
  28.     lock = Lock()
  29.     A = [Array(Point, L[:], lock=lock)]
  30.     B = L[:]
  31.  
  32.     start = ttt()
  33.     py(B)
  34.     stop = ttt()
  35.     print (stop-start)
  36.  
  37.     p = Process(target=ct, args=(A))
  38.  
  39.     start = ttt()
  40.     p.start()
  41.     p.join()
  42.     stop = ttt()
  43.     print (stop-start)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement