《CPython Internals》学习第 18天,p353-p355 总结,总计 3 页。
一、技术总结
1.benchmark(基准测试)
Python中常用的 benchmark 有 timeit, pyperformance。
(1)timeit
$ ./python -m timeit -c “x=1; x+=1; x**x”
1000000 loops, best of 5: 258 nsec per loop
我觉得这是一个很糟糕的示例,没有看出这个示例有什么意义。对于timeit 模块,我更希望放在整个项目中去看,看看它在实际项目中的应用。很遗憾,截止到目前,在我所看过的书中,关于 timeit 的使用都是测试一些代码片段。
(2)关于timeit的一点说明
作者在第356也说“You might notice a minor (1-5%) improvement in performance.”——我觉得作者在这里的叙述有点本末倒置,timeit顶多算是验证结果的一种手段,其实应该把重点放在“为什么性能提升了1-5%”。
2.profiler
Python 中常用的 profiler 有 cProfiler 或者 dtrace。
二、英语总结(生词:2)
1.detrimental
(1)detriment: de-(“away”) + terere(“to rub(摩擦), wear(to become weaker)”)
u. harm or damage. Detriment refects the sense of sth being gradually worn away(使…磨损),leading to harm or less。
(2)de

最低0.47元/天 解锁文章
514

被折叠的 条评论
为什么被折叠?



