• python-jit(提高代码运行速度)


    #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))
  • 相关阅读:
    mysql忘记root密码解决办法
    laravel 获取所有表名
    跳转/传值(从页面到php文件)
    smarty foreach
    radio单选框
    dedecms实例化对象
    file_get_contents()
    if($a)
    bug解决思路
    git查看远程仓库地址
  • 原文地址:https://www.cnblogs.com/zhouzetian/p/11446873.html
Copyright © 2020-2023  润新知