Skip to content

Commit 0cdfa56

Browse files
committed
Fixing problem with example sorting experiment.
1 parent 010303f commit 0cdfa56

6 files changed

Lines changed: 2023 additions & 1995 deletions

File tree

examples/sorting-speed/paper.pdf

54 Bytes
Binary file not shown.

examples/sorting-speed/paper.tex

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@
4949

5050
%% MULTIPLOT(algo) SELECT LOG(2, size) AS x, MEDIAN(time / repeats / size * 1e9) AS y, MULTIPLOT
5151
%% FROM stats GROUP BY MULTIPLOT,x ORDER BY MULTIPLOT,x
52-
\addplot coordinates { (10,52.6541) (11,54.4712) (12,55.6132) (13,57.2541) (14,60.2207) (15,62.5536) (16,63.3866) (17,64.8955) (18,68.0408) (19,71.5148) (20,74.3139) (21,80.9988) (22,92.9332) (23,119.146) (24,177.475) (25,310.999) (26,348.729) (27,395.465) (28,448.193) (29,509.227) (30,576.299) };
52+
\addplot coordinates { (10,71.6615) (11,77.5939) (12,83.8065) (13,89.5691) (14,95.9241) (15,102.562) (16,109.495) (17,118.608) (18,129.266) (19,139.672) (20,151.737) (21,168.85) (22,199.766) (23,237.565) (24,274.479) (25,311.786) (26,352.004) (27,398.075) (28,452.284) (29,514.045) (30,581.396) };
5353
\addlegendentry{algo=std::heap\_sort};
54-
\addplot coordinates { (10,9.53844) (11,10.2281) (12,10.8056) (13,11.73) (14,12.5076) (15,13.1773) (16,13.9202) (17,14.7259) (18,15.7581) (19,16.9725) (20,18.7205) (21,21.719) (22,27.0947) (23,37.3578) (24,58.0028) (25,100.04) (26,103.915) (27,106.265) (28,110.105) (29,113.754) (30,117.47) };
54+
\addplot coordinates { (10,37.9929) (11,42.9001) (12,47.8324) (13,51.2096) (14,55.5614) (15,59.3466) (16,63.2313) (17,67.0138) (18,70.8553) (19,74.6909) (20,78.6448) (21,82.4893) (22,86.4092) (23,90.1377) (24,93.8964) (25,98.3199) (26,102.219) (27,106.035) (28,109.866) (29,113.705) (30,117.649) };
5555
\addlegendentry{algo=std::sort};
56-
\addplot coordinates { (10,17.5403) (11,18.9741) (12,20.8212) (13,22.5908) (14,25.2842) (15,27.2218) (16,29.3958) (17,30.9679) (18,33.3819) (19,35.364) (20,40.7699) (21,44.7148) (22,49.4075) (23,56.5833) (24,69.603) (25,92.3091) (26,96.3424) (27,99.2067) (28,103.255) (29,106.148) (30,110.22) };
56+
\addplot coordinates { (10,38.0611) (11,41.7566) (12,45.1556) (13,48.2661) (14,52.3302) (15,55.3477) (16,58.915) (17,62.1703) (18,65.7791) (19,68.9638) (20,73.0819) (21,77.2482) (22,82.1805) (23,85.7273) (24,89.7738) (25,92.6328) (26,96.7431) (27,99.6031) (28,103.699) (29,106.563) (30,110.559) };
5757
\addlegendentry{algo=std::stable\_sort};
5858

5959
\end{axis}
@@ -70,39 +70,39 @@
7070
%% (SELECT MEDIAN(time / repeats / size * 1e9) FROM stats s1 WHERE s1.algo='std::heap_sort' AND s1.size = s.size GROUP BY s1.size)
7171
%% FROM stats s
7272
%% GROUP BY s.size ORDER BY s.size
73-
$2^{10}$ & \bf 9.5 & 17.5 & 52.7 \\
74-
$2^{11}$ & \bf 10.2 & 19.0 & 54.5 \\
75-
$2^{12}$ & \bf 10.8 & 20.8 & 55.6 \\
76-
$2^{13}$ & \bf 11.7 & 22.6 & 57.3 \\
77-
$2^{14}$ & \bf 12.5 & 25.3 & 60.2 \\
78-
$2^{15}$ & \bf 13.2 & 27.2 & 62.6 \\
79-
$2^{16}$ & \bf 13.9 & 29.4 & 63.4 \\
80-
$2^{17}$ & \bf 14.7 & 31.0 & 64.9 \\
81-
$2^{18}$ & \bf 15.8 & 33.4 & 68.0 \\
82-
$2^{19}$ & \bf 17.0 & 35.4 & 71.5 \\
83-
$2^{20}$ & \bf 18.7 & 40.8 & 74.3 \\
84-
$2^{21}$ & \bf 21.7 & 44.7 & 81.0 \\
85-
$2^{22}$ & \bf 27.1 & 49.4 & 92.9 \\
86-
$2^{23}$ & \bf 37.4 & 56.6 & 119.1 \\
87-
$2^{24}$ & \bf 58.0 & 69.6 & 177.5 \\
88-
$2^{25}$ & 100.0 & \bf 92.3 & 311.0 \\
89-
$2^{26}$ & 103.9 & \bf 96.3 & 348.7 \\
90-
$2^{27}$ & 106.3 & \bf 99.2 & 395.5 \\
91-
$2^{28}$ & 110.1 & \bf 103.3 & 448.2 \\
92-
$2^{29}$ & 113.8 & \bf 106.1 & 509.2 \\
93-
$2^{30}$ & 117.5 & \bf 110.2 & 576.3 \\
73+
$2^{10}$ & \bf 38.0 & 38.1 & 71.7 \\
74+
$2^{11}$ & 42.9 & \bf 41.8 & 77.6 \\
75+
$2^{12}$ & 47.8 & \bf 45.2 & 83.8 \\
76+
$2^{13}$ & 51.2 & \bf 48.3 & 89.6 \\
77+
$2^{14}$ & 55.6 & \bf 52.3 & 95.9 \\
78+
$2^{15}$ & 59.3 & \bf 55.3 & 102.6 \\
79+
$2^{16}$ & 63.2 & \bf 58.9 & 109.5 \\
80+
$2^{17}$ & 67.0 & \bf 62.2 & 118.6 \\
81+
$2^{18}$ & 70.9 & \bf 65.8 & 129.3 \\
82+
$2^{19}$ & 74.7 & \bf 69.0 & 139.7 \\
83+
$2^{20}$ & 78.6 & \bf 73.1 & 151.7 \\
84+
$2^{21}$ & 82.5 & \bf 77.2 & 168.9 \\
85+
$2^{22}$ & 86.4 & \bf 82.2 & 199.8 \\
86+
$2^{23}$ & 90.1 & \bf 85.7 & 237.6 \\
87+
$2^{24}$ & 93.9 & \bf 89.8 & 274.5 \\
88+
$2^{25}$ & 98.3 & \bf 92.6 & 311.8 \\
89+
$2^{26}$ & 102.2 & \bf 96.7 & 352.0 \\
90+
$2^{27}$ & 106.0 & \bf 99.6 & 398.1 \\
91+
$2^{28}$ & 109.9 & \bf 103.7 & 452.3 \\
92+
$2^{29}$ & 113.7 & \bf 106.6 & 514.0 \\
93+
$2^{30}$ & 117.6 & \bf 110.6 & 581.4 \\
9494
% END TABULAR SELECT '$2^{' || FLOOR(LOG(2, size)) || '}$' AS x, (SELECT MEDI...
9595
\end{tabular}
9696
\caption{Runtime per element for different sorting implementation, median of 15 runs.}
9797
\end{table}
9898

9999
\begin{comment}
100100
% TEXTTABLE SELECT COUNT(*), SUM(time) FROM stats
101-
+-------+--------------+
102-
| count | sum |
103-
+-------+--------------+
104-
| 945 | 24504.381188 |
105-
+-------+--------------+
101+
+-------+-------------+
102+
| count | sum |
103+
+-------+-------------+
104+
| 945 | 25661.41392 |
105+
+-------+-------------+
106106
% END TEXTTABLE SELECT COUNT(*), SUM(time) FROM stats
107107
\end{comment}
108108

examples/sorting-speed/sorting-speed.cpp

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,38 +85,66 @@ void run_test(const std::string& algoname)
8585
for (size_t iter = 0; iter < iterations; ++iter)
8686
{
8787
std::cout << "iteration=" << iter << "\n";
88-
88+
8989
item_type* array = new item_type[size];
9090

9191
for (size_t i = 0; i < size; ++i)
92-
array[i] = i;
92+
array[i] = i / 4;
9393

9494
std::random_shuffle(array, array + size);
9595

96-
item_type* arraycopy = new item_type[size];
97-
98-
double ts1 = timestamp();
96+
double ts1, ts2;
9997

100-
for (size_t r = 0; r < repeats; ++r)
98+
if (repeats == 1)
10199
{
102-
// copy in new version of random permutation
103-
std::copy(array, array + size, arraycopy);
100+
ts1 = timestamp();
104101

105102
test(array, size);
103+
104+
ts2 = timestamp();
106105
}
106+
else
107+
{
108+
item_type* arraycopy = new item_type[size];
109+
std::copy(array, array + size, arraycopy);
110+
111+
ts1 = timestamp();
112+
113+
for (size_t r = 0; r < repeats; ++r)
114+
{
115+
// copy in new version of random permutation
116+
std::copy(arraycopy, arraycopy + size, array);
107117

108-
double ts2 = timestamp();
118+
test(array, size);
119+
}
120+
121+
ts2 = timestamp();
122+
123+
// measure time of copying data
124+
for (size_t r = 0; r < repeats; ++r)
125+
{
126+
size_t rx = r % size;
127+
std::copy(arraycopy, arraycopy + size - rx, array + rx);
128+
}
129+
130+
double ts3 = timestamp();
131+
132+
ts2 -= ts3 - ts2;
133+
134+
volatile item_type x = array[size-1]; // anti-optimization
135+
x = x + 1;
136+
137+
delete [] arraycopy;
138+
}
109139

110-
std::cout << "time = " << ts2-ts1 << std::endl;
140+
std::cout << "time = " << ts2 - ts1 << std::endl;
111141

112-
delete [] arraycopy;
113142
delete [] array;
114143

115144
std::cout << "RESULT"
116145
<< " algo=" << algoname
117146
<< " size=" << size
118-
<< " size_log2=" << log(size) / log(2)
119-
<< " time=" << ts2-ts1
147+
<< " time=" << ts2 - ts1
120148
<< " repeats=" << repeats
121149
<< " iteration=" << iter
122150
<< " typesize=" << sizeof(item_type)

examples/sorting-speed/speed-data.txt

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -12,74 +12,74 @@
1212
# MULTIPLOT(algo) SELECT LOG(2, size) AS x, MEDIAN(time / repeats / size * 1e9) AS y, MULTIPLOT FROM stats GROUP BY MULTIPLOT,x ORDER BY MULTIPLOT,x
1313
#
1414
# index 0 algo=std::heap_sort
15-
10.0000000000000000 52.6541471481323
16-
11.0000000000000000 54.4711947441101
17-
12.0000000000000000 55.6132197380066
18-
13.0000000000000000 57.2541356086731
19-
14.0000000000000000 60.2206587791443
20-
15.0000000000000000 62.5535845756531
21-
16.0000000000000000 63.3865594863892
22-
17.0000000000000000 64.8954510688782
23-
18.0000000000000000 68.0407881736755
24-
19.0000000000000000 71.5148448944092
25-
20.0000000000000000 74.3138790130615
26-
21.0000000000000000 80.9988379478455
27-
22.0000000000000000 92.933177947998
28-
23.0000000000000000 119.145512580872
29-
24.0000000000000000 177.474915981293
30-
25.0000000000000000 310.999155044556
31-
26.0000000000000000 348.728895187378
32-
27.0000000000000000 395.464897155762
33-
28.0000000000000000 448.193401098251
34-
29.0000000000000000 509.226694703102
35-
30.0000000000000000 576.29868388176
15+
10.0000000000000000 71.6614723205566
16+
11.0000000000000000 77.5939226150513
17+
12.0000000000000000 83.8065147399902
18+
13.0000000000000000 89.569091796875
19+
14.0000000000000000 95.9241390228271
20+
15.0000000000000000 102.562010288239
21+
16.0000000000000000 109.494626522064
22+
17.0000000000000000 118.607580661774
23+
18.0000000000000000 129.266381263733
24+
19.0000000000000000 139.672458171844
25+
20.0000000000000000 151.737034320831
26+
21.0000000000000000 168.850123882294
27+
22.0000000000000000 199.766457080841
28+
23.0000000000000000 237.565040588379
29+
24.0000000000000000 274.478793144226
30+
25.0000000000000000 311.785936355591
31+
26.0000000000000000 352.004170417786
32+
27.0000000000000000 398.074835538864
33+
28.0000000000000000 452.283769845963
34+
29.0000000000000000 514.045357704163
35+
30.0000000000000000 581.39581233263
3636

3737

3838
# index 1 algo=std::sort
39-
10.0000000000000000 9.5384418964386
40-
11.0000000000000000 10.2280676364899
41-
12.0000000000000000 10.805606842041
42-
13.0000000000000000 11.7300450801849
43-
14.0000000000000000 12.5076472759247
44-
15.0000000000000000 13.1772756576538
45-
16.0000000000000000 13.9202177524567
46-
17.0000000000000000 14.725923538208
47-
18.0000000000000000 15.7581269741058
48-
19.0000000000000000 16.972541809082
49-
20.0000000000000000 18.7204778194427
50-
21.0000000000000000 21.7189788818359
51-
22.0000000000000000 27.094691991806
52-
23.0000000000000000 37.3578071594238
53-
24.0000000000000000 58.002769947052
54-
25.0000000000000000 100.039541721344
55-
26.0000000000000000 103.915482759476
56-
27.0000000000000000 106.265395879745
57-
28.0000000000000000 110.10468006134
58-
29.0000000000000000 113.754346966743
59-
30.0000000000000000 117.4695789814
39+
10.0000000000000000 37.9928946495056
40+
11.0000000000000000 42.9001450538635
41+
12.0000000000000000 47.8324294090271
42+
13.0000000000000000 51.2096285820007
43+
14.0000000000000000 55.561363697052
44+
15.0000000000000000 59.3465566635132
45+
16.0000000000000000 63.2312893867493
46+
17.0000000000000000 67.0138001441956
47+
18.0000000000000000 70.8553194999695
48+
19.0000000000000000 74.6908783912659
49+
20.0000000000000000 78.6447525024414
50+
21.0000000000000000 82.4892520904541
51+
22.0000000000000000 86.4091515541077
52+
23.0000000000000000 90.1377201080322
53+
24.0000000000000000 93.8963890075684
54+
25.0000000000000000 98.319947719574
55+
26.0000000000000000 102.21928358078
56+
27.0000000000000000 106.035172939301
57+
28.0000000000000000 109.865516424179
58+
29.0000000000000000 113.705173134804
59+
30.0000000000000000 117.6493242383
6060

6161

6262
# index 2 algo=std::stable_sort
63-
10.0000000000000000 17.5403356552124
64-
11.0000000000000000 18.9740657806396
65-
12.0000000000000000 20.821213722229
66-
13.0000000000000000 22.5907564163208
67-
14.0000000000000000 25.2841711044312
68-
15.0000000000000000 27.2217988967896
69-
16.0000000000000000 29.3958187103271
70-
17.0000000000000000 30.9678912162781
71-
18.0000000000000000 33.3818793296814
72-
19.0000000000000000 35.364031791687
73-
20.0000000000000000 40.7698750495911
74-
21.0000000000000000 44.7148084640503
75-
22.0000000000000000 49.4074821472168
76-
23.0000000000000000 56.5832853317261
77-
24.0000000000000000 69.6030259132385
78-
25.0000000000000000 92.3091173171997
79-
26.0000000000000000 96.3424146175385
80-
27.0000000000000000 99.2067158222198
81-
28.0000000000000000 103.254988789558
82-
29.0000000000000000 106.148049235344
83-
30.0000000000000000 110.220164060593
63+
10.0000000000000000 38.0611419677734
64+
11.0000000000000000 41.7566299438477
65+
12.0000000000000000 45.1555848121643
66+
13.0000000000000000 48.2660531997681
67+
14.0000000000000000 52.3301959037781
68+
15.0000000000000000 55.3476810455322
69+
16.0000000000000000 58.9150190353394
70+
17.0000000000000000 62.1703267097473
71+
18.0000000000000000 65.7790899276733
72+
19.0000000000000000 68.9637660980225
73+
20.0000000000000000 73.0818510055542
74+
21.0000000000000000 77.248215675354
75+
22.0000000000000000 82.1805000305176
76+
23.0000000000000000 85.7272744178772
77+
24.0000000000000000 89.7738337516785
78+
25.0000000000000000 92.6327705383301
79+
26.0000000000000000 96.743106842041
80+
27.0000000000000000 99.6030867099762
81+
28.0000000000000000 103.699043393135
82+
29.0000000000000000 106.562674045563
83+
30.0000000000000000 110.559165477753
8484

8585

examples/sorting-speed/speed.pdf

23 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)