#coding:utf-8
import time
from numba import jit
import pandas as pd
# from numba import autojit
# @autojit #能对所有类型的参数进行运算
@jit #即时编译,产生的函数只能对指定类型的参数进行运算
def foo():
i = 0
for a in range(200000000):
i += 1
@jit #可同时使用多个@jit
def foo2():
for a in range(200000000):
continue
# if __name__ == '__main__':
# start = time()
# foo()
# end = time()
# shi = end-start
# start2 = time()
# foo2()
# end2 = time()
# shi2 = end2-start2
# print("foo()总耗时:%s秒" % shi) # 7.158811807632446秒
# print("foo2()总耗时:%s秒" % shi2) # 3.4891695976257324秒
# 在jit装饰器的函数中,不可以使用第三方的packpage
# @jit
# def time_com(i):
# cum = 0
# for test in range(i):
# for ind in range(i):
# cum += (test * ind) % 3
# return cum
# t1 = time.clock()
# df = pd.DataFrame()
# for i in range(1000):
# print(time_com(i))
# t2 = time.clock()
#
# print("run time:%f s" % (t2 - t1)) # run time:24.704479 s
@jit
def fib(n):
if n <= 2:
return 1
else:
return fib(n-1) + fib(n-2)
start = time.clock()
print(fib(30))
end = time.clock()
print("user time:{} s".format(end-start))