4 Experimental results
4.1 Quick sort. We rst analyze the dependence of
the version of Quick sort shown in Figure 1 on the
number of inversions in the input.
Figure 4 shows our data for the AMD Athlon ar-
chitecture. The number of comparisons is independent
of the number of inversions in the input, as expected.
For the number of element swaps, the plot is very
close to linear when considering the input sequence with
small di's. Since the x-axis shows log(Inv), this is in very
good correspondence with the bound O(n log(Inv=n))
of Theorem 1.1 (recall that n is xed in the plot). For
the input sequence with large di's, the plot is dierent.
This is a sign of the slack in the analysis (for this type
of input) noted after the proof of Theorem 1.1. We
will demonstrate below that this curve is in very good
correspondence with the version of the bound given by
Equation (2.2). The plots for the number of branch mis-
predictions and for the running time clearly show that
they are correlated with the number of element swaps.
For the number of branch mispredictions, this is ex-
plained by the fact that an element swap is performed
after the two while loops stop, and hence corresponds
to two branch mispredictions. For the running time,
it seems reasonable to infer that branch mispredictions
are a dominant part of the running time of Quicksort on
this type of architecture. Finally, the number of data
cache misses seems independent of the presortedness of
the input sequence, in correspondence with the fact that
for all element swaps, the data to be manipulated is al-
ready in the cache and therefore the element swaps do
not generate additional cache misses.
Figure 5 show the same plots for the P4 architec-
ture, except that we were not able to obtain data for
L2 data cache misses. We note that the plots follow the
same trends as in Figure 4. The number of comparisons
and the number of element swaps are approximately the
same, but the running time is aected by up to a factor
of 1:8 on the P4, while only by up to a factor of 1:42 on
the Athlon. One reason for this behavior is the number
of branch mispredictions, which is slightly smaller for
the Athlon. Also, the length of the pipeline, shorter for
Athlon, makes the branch mispredictions more costly
on a P4 than on an Athlon.
Similar observations on the resemblance between
the data for the two architectures apply to all our
experiments. For this reason, and because of the
extra data for L2 that we have for Athlon, we for
the remaining plots restrict ourselves to the Athlon
architecture.
We now turn to the variants of Quicksort. Figure 6
shows the number comparisons, the number of element
swaps, the number of branch mispredictions, the run-
ning time, and the L2 data cache misses for the version
of Quicksort that chooses as pivot the median of three
random elements in the input sequence. We note that
the plots have a behavior similar to the ones for the ver-
sion of Quicksort shown in Figure 4. However, some im-
provements are noticed. The three-median pivot Quick-
sort performs around 25% less comparisons, due to the
better choice of the pivot. This immediately triggers a
slight improvement in the number of data cache misses.
However, the number of branch mispredictions increases
due to the extra branches required to compute the me-
dian of three elements. The number of element swaps
remains approximately the same.
Figure 7 shows the same plots for the determin-
istic version of Quicksort that chooses the middle el-
ement as pivot. In this case we note that the num-
ber of comparisons does depend on the presortedness
of the input. This is because for small disorder, the
middle element is very close to the median and there-
fore the number of comparisons is close to n log n, as
opposed to 1:4n log n expected for the randomized
Quicksort [10]. The good pivot choice for small disorder
in the input also triggers a smaller number of compar-
isons and branch mispredictions. However, for large dis-
order, the number of comparisons is larger compared to
randomized median-of-three Quicksort due to bad pivot
choices. Also, the running time is aected by up to a
factor of two by the disorder in the input.
Figure 8 and Figure 9 show that when varying the
input size n, the behavior of the plots remains the same
for randomized Quicksort. Hence, our ndings do not
seem to be tied to the particular choice of n = 2 106.
Finally, in Figure 10 we demonstrate that the
number of element swaps is very closely related to
Pn
i=1 log di, cf. the comment after the proof of Theo-
rem 1.1. Hence the reason for the non-linear shape of
the previous plots for input sequences with large di's
seems to be the slack introduced (for this type of input)
after Equation (2.2) in the proof of Theorem 1.1. As
in the other cases, the running time and the number
of branch mispredictions follow the same trend as the
number of swaps.
4 การทดลอง
4.1 ด่วนประเภท เรา RST วิเคราะห์การพึ่งพาอาศัยกันของ
รุ่นเร็ว เรียงแสดงในรูปที่ 1 ใน
จำนวน inversions ในการป้อนข้อมูล
รูปที่ 4 แสดงข้อมูลสำหรับ AMD Athlon AR -
chitecture . จำนวนของการเปรียบเทียบเป็นอิสระ
จำนวน inversions ในการป้อนข้อมูลตามที่คาดหวัง .
สำหรับหมายเลขแลกเปลี่ยนองค์ประกอบพล็อตมาก
ใกล้เชิงเส้น เมื่อพิจารณาลำดับใส่กับ
ขนาดเล็ก di . ตั้งแต่แกน x แสดง log ( INV ) , มีมาก
จดหมายที่ดีกับผูกพัน O ( n log ( N = N )
ทฤษฎีบท 1.1 ( จำได้ว่าเป็น xed ในพล็อต ) สำหรับลำดับใส่
ขนาดใหญ่ di , แปลงเป็น ดิ erent .
นี้เป็นสัญญาณของเวลาในการวิเคราะห์ ( ชนิดนี้
ใส่ ) กล่าวหลังจากพิสูจน์ทฤษฎีบท 1.1 . เรา
จะแสดงด้านล่างที่โค้งนี้มีมาก
ติดต่อกับรุ่นไว้ให้โดย
สมการ ( 2.2 ) แปลงสำหรับจำนวนของสาขา MIS -
คาดคะเนและสำหรับเวลา แสดงให้เห็นชัดเจนว่าพวกเขามีความสัมพันธ์กับ
จำนวนองค์ประกอบ swaps .
สำหรับจำนวนของ mispredictions สาขา ซึ่งเป็นอดีต -
plained โดยความจริงที่ว่าองค์ประกอบสลับแสดง
หลังจากที่ทั้งสองในขณะที่ลูปหยุดและด้วยเหตุนี้สอดคล้อง
2 สาขา mispredictions . สำหรับวิ่งเวลา
ดูเหมือนว่าเหมาะสมที่จะอนุมานว่า mispredictions สาขา
เป็นส่วนเด่นของเวลาการทำงานของควิกซอร์ตบน
สถาปัตยกรรมประเภทนี้ ในที่สุดจำนวนของข้อมูล
แคชคิดถึงดูอิสระของ presortedness ของ
ใส่ลำดับในการติดต่อกับความเป็นจริงที่
สำหรับการแลกเปลี่ยนธาตุทั้งหมด ข้อมูลที่ถูก คือ อัล -
พร้อมในแคชและดังนั้นองค์ประกอบการทำ
ไม่สร้างแคชเพิ่มเติมพลาด รูปที่ 5 แสดงเดียวกันแปลงสำหรับ P4 engineer -
จริง ยกเว้นว่าเราไม่สามารถรับข้อมูลสำหรับแคช L2
ข้อมูลพลาด เราทราบว่าแปลงตามแนวโน้ม
เหมือนในรูปที่ 4 จำนวนของการเปรียบเทียบ
และจำนวนของการแลกเปลี่ยนธาตุประมาณ
เหมือนกัน แต่เวลาวิ่งเป็น ประมวลถึงปัจจัยของบน P4
8 ในขณะที่เพียงโดยขึ้นอยู่กับปัจจัย 1:42 บน
Athlon . หนึ่งในเหตุผลสำหรับพฤติกรรมนี้เป็นหมายเลข
ของ mispredictions สาขาซึ่งเล็กกว่าเล็กน้อยสำหรับ
Athlon . นอกจากนี้ ความยาวของท่อ , สั้นสำหรับ
โพรเซสเซอร์ ทำให้ราคาแพงมากขึ้น
mispredictions สาขาบน P4 กว่า Athlon .
สังเกตที่คล้ายกันในความเหมือนกันระหว่างข้อมูลสองสถาปัตยกรรมสมัครทดลองของเรา
. ด้วยเหตุนี้และเนื่องจาก
ข้อมูลพิเศษสำหรับ L2 ที่เรามีข้อมูล เราสำหรับ
แปลงที่เหลือ จำกัด ตัวเองเพื่อ Athlon
ตอนนี้เราเปิดสถาปัตยกรรม รูปของควิกซอร์ต . รูปที่ 6
แสดงจํานวนการเปรียบเทียบจำนวนขององค์ประกอบ
swaps จำนวน mispredictions สาขา , วิ่ง -
หนิงเวลาและข้อมูล L2 แคชขาดหายไปสำหรับรุ่นที่เลือกเป็นเดือยของควิกซอร์ต
3
ค่ามัธยฐานขององค์ประกอบในการสุ่มลำดับ เราทราบว่า
แปลงมีพฤติกรรมคล้ายกับสำหรับ Ver -
ไซออนของควิกซอร์ตแสดงในรูปที่ 4 อย่างไรก็ตาม อิม -
provements จะสังเกตเห็น 3 หมุนเร็ว -
มัธยฐานจัดเรียงแสดงประมาณ 25% เปรียบเทียบน้อย เนื่องจาก
ทางเลือกที่ดีของเดือย เดี๋ยวนี้เรียก
การปรับปรุงเล็กน้อยในหมายเลขของแคชข้อมูลคิดถึง .
แต่จำนวนสาขาเพิ่มขึ้น mispredictions
จากพิเศษสาขาต้องคำนวณฉัน -
เถียนสามองค์ประกอบ จำนวนของการแลกเปลี่ยนองค์ประกอบยังคงประมาณเดียวกัน
.รูปที่ 7 แสดงเดียวกันแปลง เพื่อทราบ -
istic รุ่นควิกซอร์ตที่จะเลือกกลาง เอล -
ซึ่งเป็นเดือย ในกรณีนี้เราทราบว่าหนุ่ม -
เบอร์มือถือจะขึ้นอยู่กับ presortedness
ของการป้อนข้อมูล นี้เป็นเพราะความผิดปกติขนาดเล็ก
กลางธาตุอยู่ใกล้กับค่ามัธยฐานและมี -
4 จำนวนเปรียบเทียบใกล้ n log n ,
นอกคอก 15 log n โดยสุ่ม
ควิกซอร์ต [ 10 ] ดีทางเลือกสำหรับโรคเดือยเล็ก
ในใส่ยังเรียกขนาดเล็กจำนวน compar -
isons และสาขา mispredictions . อย่างไรก็ตาม สำหรับขนาดใหญ่ dis -
สั่งซื้อ จำนวนของการเปรียบเทียบมีขนาดใหญ่เมื่อเทียบกับค่าเฉลี่ยของทั้งสามคน
เลือกควิกซอร์ตเนื่องจากหมุนไม่ดี นอกจากนี้ เวลาทํางานเป็น ประมวลถึง
โดยปัจจัยที่สอง โดยความผิดปกติในการป้อนข้อมูล .
รูปที่ 8 และรูปที่ 9 แสดงให้เห็นว่าเมื่อเปลี่ยนแปลง
ใส่ขนาด N , พฤติกรรมของแปลงยังคงเหมือนเดิม
สำหรับแบบควิกซอร์ต . ดังนั้น ndings ของเราไม่
ดูเหมือนจะเชื่อมโยงกับทางเลือกเฉพาะของ n = 2 106 .
ในที่สุด ในรูปที่ 10 เราแสดงให้เห็นว่า
เลขที่แลกเปลี่ยนองค์ประกอบที่เกี่ยวข้องอย่างใกล้ชิดกับ PN
= 1 DI CFแสดงความคิดเห็นหลังพิสูจน์ของ Theo -
เรม 1.1 . ดังนั้นเหตุผลที่รูปร่างแบบไม่เชิงเส้นของ
แปลงก่อนหน้านี้ สำหรับข้อมูลที่มีขนาดใหญ่เป็นลำดับ ดิ
ดูเหมือนจะหย่อนแนะนำ ( สำหรับข้อมูลประเภทนี้ )
หลังจากที่สมการ ( 2.2 ) ในการพิสูจน์ทฤษฎีบท 1.1 . โดย
ในบางกรณี เวลา และหมายเลขของ mispredictions
สาขาเป็นไปตามแนวโน้มเดียวกับ
จำนวน swaps
การแปล กรุณารอสักครู่..
