Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tuple_ctypes_timeit.py
- from multiprocessing import Process, Lock
- from multiprocessing.sharedctypes import Value, Array
- from ctypes import Structure, c_double
- from random import randint
- from time import clock as ttt
- t = 100000
- def rXY():
- return (randint(0,800), randint(0,1280))
- L = [rXY() for z in range(t)]
- class Point(Structure):
- _fields_ = [('x', c_double), ('y', c_double)]
- def ct(A):
- for a in A:
- a.x = 2
- a.y = 4
- def py(B):
- for b in range(len(B)):
- B[b] = 3,6
- if __name__ == '__main__':
- lock = Lock()
- A = [Array(Point, L[:], lock=lock)]
- B = L[:]
- start = ttt()
- py(B)
- stop = ttt()
- print (stop-start)
- p = Process(target=ct, args=(A))
- start = ttt()
- p.start()
- p.join()
- stop = ttt()
- print (stop-start)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement