Advertisement
here2share

# ctype_speedtest.py

Jan 16th, 2019
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. # ctype_speedtest.py
  2.  
  3. import ctypes
  4. import ctypes.util
  5. import time
  6.  
  7. clib = ctypes.util.find_library('c')
  8. sumrange_ctypes = ctypes.cdll.LoadLibrary(clib)
  9. sumrange_ctypes.restype = ctypes.c_ulonglong
  10.  
  11. def test(t):
  12.     return int(t)+1
  13. 0
  14. def res(s):
  15.     print "%s: %s cycles in 2 seconds" % (s, c)
  16. 0
  17.  
  18. for i in 'z'*6:
  19.     c = 1
  20.     start_time = time.time()
  21.     while time.time() - start_time < 2:
  22.         c = test(c) # how to run this in ctypes ???
  23.     res('C-Type')
  24.  
  25.     c = 1
  26.     start_time = time.time()
  27.     while time.time() - start_time < 2:
  28.         c = test(c)
  29.     res('Python')
  30.     print
  31.  
  32. #'''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement