Advertisement
here2share

# globals_timed.py

Mar 31st, 2021
1,104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. # globals_timed.py ??? dang!
  2.  
  3. from ctypes import *
  4. import timeit
  5.  
  6. def f1():
  7.     global t
  8.     t += 1
  9.  
  10. def f2():
  11.     cv.t += 1
  12.  
  13. def f3():
  14.     p[0] += 1
  15.  
  16. class Cv(): 0
  17. cv = Cv()
  18. cv.t = 0
  19. t = 0
  20. n = c_int(0)
  21. p = pointer(n)
  22.  
  23. for i in '.'*10:
  24.     print(timeit.timeit("f1()", setup="from __main__ import f1"))
  25.     print(timeit.timeit("f2()", setup="from __main__ import f2"))
  26.     print(timeit.timeit("f3()", setup="from __main__ import f3"))
  27.     print
  28.  
  29. print(t)
  30. print(cv.t)
  31. print(n.value)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement