Python Code Acceleration(Python代码加速)

对于Python的代码执行效率较低的问题,参考博客:https://developer.51cto.com/art/201809/583695.htm进行相应的测试。

参考代码如下:

from numba import jit
import time

def foo(x,y):
  tt = time.time()
  s = 0
  for i in range(x,y):
    s += i
  print('Time used: {} sec'.format(time.time()-tt))
  return s

print(foo(1,100000000))

输出时间:

Time used: 3.7836766242980957 sec
4999999950000000

加入代码:

from numba import jit
import time
@jit
def foo(x,y):
  tt = time.time()
  s = 0
  for i in range(x,y):
    s += i
  print('Time used: {} sec'.format(time.time()-tt))
  return s

print(foo(1,100000000))

输出时间:

Time used: 0.02804708480834961 sec
4999999950000000

这个时间很可观了,very very fast!!!对于时间的进一步优化以及使用明天再来详细研究。

 I hope I can help you,If you have any questions, please  comment on this blog or send me a private message. I will reply in my free time.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值