- pypy 不需要修改代码 直接执行
- numba 安装 修改少数代码可以得到大幅提升
- Cython 需要编译成c语言同时有加密代码作用
#!/usr/bin/env python
#-*-coding:utf-8-*-
#原版代码
import time
import pandas as pd
def time_com(i):
cum = 0
for test in range(i):
for ind in range(i):
cum += (test * ind) % 3
if __name__ == '__main__':
t1 = time.clock()
df = pd.DataFrame()
for i in range(500):
time_com(i)
t2 = time.clock()
print "run time:%f s" % (t2 - t1)
#!/usr/bin/env python
#-*-coding:utf-8-*-
# 使用numba 加速代码
import time
import pandas as pd
from numba import jit
@jit
def time_com(i):
cum = 0
for test in range(i):
for ind in range(i):
cum += (test * ind) % 3
if __name__ == '__main__':
t1 = time.clock()
df = pd.DataFrame()
for i in range(500):
time_com(i)
t2 = time.clock()
print "run time:%f s" % (t2 - t1)
网友评论