http://qiita.com/open_cans/items/f180ae4dc945dc7b9066 This is a continuation of this article. I mainly write for people who care about milliseconds and microseconds.
numba is a guy who compiles python code with a jit compiler to make it faster A pretty amazing guy who can speed up very easily
sample.py
import numba
@numba.jit
def sumation(num):
sum=0
for i in range(num):
sum += i
return sum
sum = sumation(100)
print(sum)
Before the function as in the third line @numba.jit Just write It's amazing how easy it is to speed up! !!
It's easy, but there are some things to keep in mind when using it, so I'll list them.
In the previous article, I wrote that the inclusion notation is the best, but it can not be used with numba. I don't think it's there, but if you look at the previous article and write the comprehension, you have to rewrite the comprehension to the for statement.
sample.py
import numba
@numba.jit
def inputList(num):
temp=[]
temp.append(num)
return sum
sum = inputList(100)
print(sum)
If you write like this, you will get an error Temp = [] is the cause
If you write @ numba.jit in a function that doesn't work in the first place, the error will be hidden and you will not be able to understand it well, so please be sure to write @ numba.jit after confirming that it works reliably.
Sometimes I try to speed up a function that uses numpy with numba, but sometimes I can't. Apparently numba is not supported by some numpy functions This article (http://nekowarau.seesaa.net/article/428663212.html) According to numba, the supported numpy functions are (http://numba.pydata.org/numba-doc/0.14/numpy_support.html) Seems to be able to confirm with
If it doesn't, write the function in scratch Then you can get the benefit of speeding up.