更快还是更慢?用经验证据揭开Python习语的性能之谜
Faster or Slower? Performance Mystery of Python Idioms Unveiled with Empirical Evidence
摘要:
Python习惯用法在Python开发人员中很受欢迎,在Stack Overflow上对101个与Python习惯用法有关的性能问题进行的形成性研究中,我们发现开发人员经常对Python习惯用法的性能影响感到困惑,并使用轶事玩具代码或依赖于个人项目经验,这在性能结果中往往是矛盾的。一直没有大规模的,系统的经验证据来调和这些性能的争论。在本文中,我们创建了一个大型的合成数据集,其中包含24,126对非惯用和功能等效的惯用代码,用于Zhang等人确定的9种独特的Python惯用法,本文提出了一种可靠的性能度量方法,比较了惯用代码与非惯用代码的性能提升或降低,分析了合成代码与真实项目代码之间的性能差异、代码特征与性能变化之间的关系以及字节码级别性能变化的根本原因。我们总结了我们的发现,作为使用Python习惯用法的一些可操作的建议。
英文摘要:
The usage of Python idioms is popular among Python developers in a formative study of 101 performance-related questions of Python idioms on Stack Overflow, we find that developers often get confused about the performance impact of Python idioms and use anecdotal toy code or rely on personal project experience which is often contradictory in performance outcomes. There has been no large-scale, systematic empirical evidence to reconcile these performance debates. In the paper, we create a large synthetic dataset with 24,126 pairs of non-idiomatic and functionally-equivalent idiomatic code for the nine unique Python idioms identified in Zhang et al., and reuse a large real-project dataset of 54,879 such code pairs provided by Zhang et al. We develop a reliable performance measurement method to compare the speedup or slowdown by idiomatic code against non-idiomatic counterpart, and analyze the performance discrepancies between the synthetic and real-project code, the relationships between code features and performance changes, and the root causes of performance changes at the bytecode level. We summarize our findings as some actionable suggestions for using Python idioms.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。