加速包
numba
包描述文件:https://numba.pydata.org/numba-doc/latest/index.html
from numba import jit
加速实例
加速前:
import time
from numba import jit
# @jit(parallel = True)
def dump():
for i in range(170):
for j in range(250):
for i_in in range(170):
for j_in in range(250):
b=1+1
return b
start = time.time()
dump()
end = time.time()
print("加速前:", end-start)
加速后:
import time
from numba import jit
@jit(parallel = True)
def dump():
for i in range(170):
for j in range(250):
for i_in in range(170):
for j_in in range(250):
b=1+1
return b
start = time.time()
dump()
end = time.time()
print("加速后:", end-start)
输出对比:
需注意!!!
此法仅限于纯粹数学运算,用到numpy等初级运算库,涉及高级python代码的可能会报错!!!!