About
sortchk is a simple test suite I wrote in order to
measure the costs (in terms of needed comparisons and data
moves, not in terms of time consumed by the algorithm, as this
is too dependend on things like type of computer, programming
language or operating system) of different sorting algorithms.
The software is meant to be easy extensible and easy to use.
It was developed on NetBSD,
but it will also compile and run well on other systems, such as
FreeBSD, OpenBSD, Darwin, AIX and Linux. With little work, it should
also be able to run on foreign plattforms such as Microsoft
Windows or MacOS 9.
Usage
The program has four options:
-a <algorithms> |
Test only the algorithms specified in
<algorithms>. Currently the following algorithms
are available: bubblesort, bubblesortbi
(a bidirectional variant of bubblesort),
selectionsort, insertionsort,
shellsort, mergesort, quicksort
(this is the quicksort algorithm by Nico Lomuto),
quicksortrnd (same as quicksort,
but with randomized median), quicksorthoare
(original quicksort algorithm by C.A.Hoare) and
heapsort. The program defaults to testing all
currently available algorithms.
|
-n <items> |
Use an array with <items> elements in
it. Defaults to 10.
|
-o <order> |
Set the initial content of the test array to
<order>, which can be one of: ascend,
descend or random. Defaults to
random.
|
-t <n> |
Run each algorithm <n> times. This
is used to archieve good average measure results.
Defaults to 10.
|
For example, run
sortchk -a bubblesort,quicksort,heapsort -o ascend -n 100
and you'll see quicksort loose, whereas heapsort does a not
that bad job.
Download
The binary packages are statically linked and compiled with
-O2, which is quite O.K. for this program. If you have
any problems using the contributed binary packages, please contact
the given maintainer instead.
NOTE: Version 0.1 includes a Quicksort algorithm named
Quicksort (Vahrenhhold). This was a mistake, the algorithm
was originally introduced by Nico Lomuto and is commonly
know as Lomuto partition algorithm. Version 0.2 of the
software therefore uses the name Quicksort (Lomuto) instead.
Feedback
I'm very interested in getting feedback on this test suite.
If you find bugs or add new sorting algorithms, please drop
me a note.
Test runs
To measure costs for huge data arrays, you need a lot of patience.
I've done some test runs and put the results here for people
to look at. Its interesting to see that heapsort is that
fast (in terms of comparisons and data moves), so why do people
always think of quicksort first?
items: 10,
order: random |
Algorithm |
Comparisons |
Data moves |
Bubblesort |
42 |
72 |
Bubblesort (bidirectional) |
47 |
72 |
Selectionsort |
45 |
27 |
Insertionsort |
30 |
42 |
Shellsort |
30 |
42 |
Mergesort |
22 |
68 |
Quicksort (Lomuto) |
26 |
70 |
Quicksort (Randomized) |
25 |
80 |
Quicksort (Hoare) |
56 |
35 |
Heapsort |
35 |
46 |
items: 100,
order: random |
Algorithm |
Comparisons |
Data moves |
Bubblesort |
4892 |
7419 |
Bubblesort (bidirectional) |
4039 |
7419 |
Selectionsort |
4950 |
297 |
Insertionsort |
2568 |
2671 |
Shellsort |
779 |
1087 |
Mergesort |
542 |
1344 |
Quicksort (Lomuto) |
686 |
1412 |
Quicksort (Randomized) |
646 |
1424 |
Quicksort (Hoare) |
1071 |
568 |
Heapsort |
384 |
434 |
items: 1000,
order: random |
Algorithm |
Comparisons |
Data moves |
Bubblesort |
498765 |
750660 |
Bubblesort (bidirectional) |
381376 |
750660 |
Selectionsort |
499500 |
2997 |
Insertionsort |
251212 |
252218 |
Shellsort |
14084 |
19177 |
Mergesort |
8699 |
19952 |
Quicksort (Lomuto) |
10617 |
18822 |
Quicksort (Randomized) |
11033 |
20472 |
Quicksort (Hoare) |
15545 |
8007 |
Heapsort |
3804 |
4214 |
items: 10000,
order: random |
Algorithm |
Comparisons |
Data moves |
Bubblesort |
49979584 |
74885447 |
Bubblesort (bidirectional) |
37619489 |
74885447 |
Selectionsort |
49995000 |
29997 |
Insertionsort |
24971805 |
24981813 |
Shellsort |
234228 |
313666 |
Mergesort |
120457 |
267232 |
Quicksort (Lomuto) |
152349 |
253604 |
Quicksort (Randomized) |
156697 |
292643 |
Quicksort (Hoare) |
208025 |
103398 |
Heapsort |
37912 |
41876 |
|