Advertisement
user_137

Untitled

May 7th, 2013
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import numpy as np
  2. from numba import autojit, jit, void, double, int_
  3.  
  4. def doloop(X,Y,mm):
  5.     for i in range(Y):
  6.         xx = mm[:]
  7.         x = 0
  8.         for j in range(X):
  9.             xx[x] = x
  10.             x += 1
  11.     return 1
  12.  
  13. looper = autojit(doloop)
  14.  
  15. if __name__ == '__main__':
  16.     X = 1000
  17.     Y = 10000000
  18.     zz = np.random.random(X)
  19.     looper(X, Y, zz)
  20.     # zz = np.random.randint(0,9,X)
  21.     # zz = [0 for i in range(X)]  # ... much slower than np array
  22.     # doloop(X,1000000,zz)
  23.     #
  24.     # 10,000,000 takes 7.6 seconds with numba
  25.     #  1,000,000   takes 166 seconds with python
  26.     #  gain = 210 times
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement