标签:10 函数 0.078 ... python percall 0.888 分析程序 0.000
目录
1. 一个函数
>>> import random
>>> lst = [random.random() for i in range(10000)]
>>> def f1(lst0):
... lst1 = sorted(lst0)
... lst2 = [i for i in lst1 if i<0.5]
... lst3 = [i*i for i in lst2]
... return lst3
2. 在脚本中测试性能:
>>> import cProfile
>>> cProfile.run('f1(lst)')
7 function calls in 0.005 seconds
Ordered by: standard name
ncalls tottime precall cumtime precall filename:lineno(function)
1 0.000 0.000 0.861 0.861 <stdin>:1(f1)
1 0.118 0.118 0.118 0.118 <stdin>:3(<listcomp>)
1 0.078 0.078 0.078 0.078 <stdin>:4(<listcomp>)
1 0.027 0.027 0.888 0.888 <string>:1(<module>)
1 0.000 0.000 0.888 0.888 {built-in method builtins...}
1 0.665 0.665 0.665 0.665 {built-in method builtins...}
1 0.000 0.000 0.000 0.000 {method 'disable' of ...}
3. 在命令行测试性能:
$ python –m cProfile test.py
4. 报告中的参数说明
参数 | 说明 |
---|---|
ncalls | 表示函数调用的次数; |
tottime | 表示指定函数的总的运行时间,除掉函数中调用子函数的运行时间; |
percall(第一个percall) | 等于 tottime/ncalls; |
cumtime | 表示该函数及其所有子函数的调用运行的时间,即函数开始调用到返回的时间; |
percall(第二个percall) | 函数运行一次的平均时间,等于 cumtime/ncalls; |
filename:lineno(function) | 每个函数调用的具体信息; |
标签:10,函数,0.078,...,python,percall,0.888,分析程序,0.000 来源: https://www.cnblogs.com/gaiqingfeng/p/13229159.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。