快速排序中分支丢失的分析
Analysis of Branch Misses in Quicksort
摘要:
算法的分析主要依赖于计算经典的基本运算,如加法,乘法,比较,交换等,这种方法通常足以量化算法的效率。然而,在某些情况下,现代处理器架构的特性(如流水线执行和存储层次结构)对运行时间有显著影响,需要考虑到这些特性才能得到可靠的结果。一个例子是Quicksort:实验证明,在硬件上的某些条件下,将枢轴作为样本的中值的经典最优平衡选择变得有害。原因在于错误预测的分支,其回滚成本成为主导。在本文中,我们给出了第一个精确的分析调查的影响,流水线和由此产生的分支预测失误的效率(经典)快速排序和雅罗斯拉夫斯基的双支点快速排序在Oracle的Java 7库中实现。对于后者,人们仍然没有完全理解为什么实验证明它比经典单枢轴版本的高度工程化实现快10%。对于不同的分支预测策略,我们给出了精确的渐近的预期数量的分支失误所造成的上述快速排序变种时,他们的枢轴是从输入的样本中选择。我们的结论是,分支未命中的差异太小,无法解释双枢轴算法的优越性。
英文摘要:
The analysis of algorithms mostly relies on counting classic elementary operations like additions, multiplications, comparisons, swaps etc. This approach is often sufficient to quantify an algorithm's efficiency. In some cases, however, features of modern processor architectures like pipelined execution and memory hierarchies have significant impact on running time and need to be taken into account to get a reliable picture. One such example is Quicksort: It has been demonstrated experimentally that under certain conditions on the hardware the classically optimal balanced choice of the pivot as median of a sample gets harmful. The reason lies in mispredicted branches whose rollback costs become dominating. In this paper, we give the first precise analytical investigation of the influence of pipelining and the resulting branch mispredictions on the efficiency of (classic) Quicksort and Yaroslavskiy's dual-pivot Quicksort as implemented in Oracle's Java 7 library. For the latter it is still not fully understood why experiments prove it 10% faster than a highly engineered implementation of a classic single-pivot version. For different branch prediction strategies, we give precise asymptotics for the expected number of branch misses caused by the aforementioned Quicksort variants when their pivots are chosen from a sample of the input. We conclude that the difference in branch misses is too small to explain the superiority of the dual-pivot algorithm.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。