Skip to content

Instantly share code, notes, and snippets.

@RiseInRose
Created October 23, 2018 05:59
Show Gist options
  • Save RiseInRose/d4ddc230bff4e94ee9cf14cfa75f6adf to your computer and use it in GitHub Desktop.
Save RiseInRose/d4ddc230bff4e94ee9cf14cfa75f6adf to your computer and use it in GitHub Desktop.
这个主要测试python在各种环境下的效率问题。
# author caturbhujadas_pc
# date 2018/10/23 13:31
# wechat chending2012
from time import time
from numba import autojit
i = range(10000000)
# @autojit()
def do(each):
# str(each)
each += 1
# int(each)
# each*each
t1 = time()
for each in i:
do(each)
print(time() - t1)
t3 = time()
[do(each) for each in i]
print(time() - t3)
t2 = time()
map(do, i)
print(time() - t2)
@RiseInRose
Copy link
Author

这个主要测试python各种内置方法的效率
测试结果:
2.5809388160705566
2.335479974746704
5.9604644775390625e-06
map的时间最短(电脑为4核)。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment