From 2aa59cce8ac3460e4fafeefd22303feb012ffa58 Mon Sep 17 00:00:00 2001 From: Brian Park Date: Thu, 5 Aug 2021 13:10:32 -0700 Subject: [PATCH 01/12] src/selectionSort.h: Add Selection Sort, mostly for completeness, not compelling compared to Insertion Sort --- CHANGELOG.md | 2 + README.md | 79 +++++++++++++++++++++---------- library.properties | 2 +- src/AceSorting.h | 1 + src/ace_sorting/selectionSort.h | 65 +++++++++++++++++++++++++ src/ace_sorting/shellSort.h | 2 +- tests/SortingTest/SortingTest.ino | 5 ++ 7 files changed, 128 insertions(+), 28 deletions(-) create mode 100644 src/ace_sorting/selectionSort.h diff --git a/CHANGELOG.md b/CHANGELOG.md index d1c1ec1..5468f4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Changelog * Unreleased + * Add Selection Sort, mostly for completeness. It's another `O(N^2)` sort + but is slower than Insertion Sort, and is not a stable sort. * v0.1 (2021-08-04) * Add `combSort133()` which uses a gap factor of 4/3, which eliminates integer division. Smaller and faster on 8-bit processors which don't have diff --git a/README.md b/README.md index 2aba403..15fbff3 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,9 @@ using C++11 templates. Supports the following algorithms: * Bubble Sort * `bubbleSort()` (not recommended) * Insertion Sort - * `insertionSort()` (recommended if N < ~100 and a stable sort is needed) + * `insertionSort()` (recommended if N < ~100 or a stable sort is needed) +* Selection Sort + * `selectionSort()` (not recommended) * Shell Sort * `shellSortClassic()`: gap factor 2 * `shellSortKnuth()`: gap factor 3 (recommended) @@ -40,6 +42,7 @@ versions which take a custom comparator. * [Include Header and Namespace](#HeaderAndNamespace) * [Bubble Sort](#BubbleSort) * [Insertion Sort](#InsertionSort) + * [Selection Sort](#SelectionSort) * [Shell Sort](#ShellSort) * [Comb Sort](#CombSort) * [Quick Sort](#QuickSort) @@ -162,6 +165,26 @@ void insertionSort(T data[], uint16_t n); * **Recommendation**: Use for N smaller than about 100 and only if you need a stable sort + +### Selection Sort + +See https://en.wikipedia.org/wiki/Selection_sort. + +```C++ +template +void selectionSort(T data[], uint16_t n); +``` + +* Flash consumption, 100 bytes on AVR +* Additional ram consumption: none +* Runtime complexity: `O(N^2)` but 2X slower than `insertionSort()` +* Stable sort: No +* **Not recommended**: + * Larger and slower than `insertionSort()` but is not a stable sort. + * The only thing it has going for it is that it has the least number of + writes versus reads. Might be worth looking into if writing the data is + much more expensive than reading the data. + ### Shell Sort @@ -306,6 +329,7 @@ The full details of flash and static memory consumptions are given in |----------------------------------------+--------------+-------------| | bubbleSort() | 1110/ 214 | 44/ 0 | | insertionSort() | 1126/ 214 | 60/ 0 | +| selectionSort() | 1166/ 214 | 100/ 0 | |----------------------------------------+--------------+-------------| | shellSortClassic() | 1164/ 214 | 98/ 0 | | shellSortKnuth() | 1208/ 214 | 142/ 0 | @@ -334,6 +358,7 @@ The full details of flash and static memory consumptions are given in |----------------------------------------+--------------+-------------| | bubbleSort() | 257164/26976 | 64/ 0 | | insertionSort() | 257164/26976 | 64/ 0 | +| selectionSort() | 257180/26976 | 80/ 0 | |----------------------------------------+--------------+-------------| | shellSortClassic() | 257196/26976 | 96/ 0 | | shellSortKnuth() | 257212/26976 | 112/ 0 | @@ -366,23 +391,24 @@ Here are 2 samples. | \ N | 10 | 30 | 100 | 300 | 1000 | 3000 | | Function \ | | | | | | | |---------------------+-------+-------+--------+---------+---------+---------| -| bubbleSort() | 0.101 | 0.989 | 11.841 | 112.304 | | | -| insertionSort() | 0.045 | 0.275 | 2.601 | 21.651 | | | +| bubbleSort() | 0.107 | 1.077 | 12.735 | 116.675 | | | +| insertionSort() | 0.045 | 0.263 | 2.557 | 22.252 | | | +| selectionSort() | 0.088 | 0.560 | 5.600 | 48.892 | | | |---------------------+-------+-------+--------+---------+---------+---------| -| shellSortClassic() | 0.090 | 0.365 | 1.797 | 7.412 | | | -| shellSortKnuth() | 0.102 | 0.329 | 1.443 | 5.728 | | | -| shellSortTokuda() | 0.074 | 0.340 | 1.631 | 6.554 | | | +| shellSortClassic() | 0.074 | 0.310 | 1.706 | 6.865 | | | +| shellSortKnuth() | 0.101 | 0.330 | 1.450 | 5.665 | | | +| shellSortTokuda() | 0.075 | 0.327 | 1.614 | 6.540 | | | |---------------------+-------+-------+--------+---------+---------+---------| -| combSort13() | 0.163 | 0.550 | 2.220 | 8.135 | | | -| combSort13m() | 0.164 | 0.551 | 2.238 | 8.141 | | | -| combSort133() | 0.085 | 0.388 | 1.950 | 7.691 | | | -| combSort133m() | 0.089 | 0.419 | 1.995 | 7.730 | | | +| combSort13() | 0.160 | 0.534 | 2.214 | 8.167 | | | +| combSort13m() | 0.165 | 0.550 | 2.219 | 8.181 | | | +| combSort133() | 0.086 | 0.396 | 1.944 | 7.702 | | | +| combSort133m() | 0.086 | 0.416 | 1.978 | 7.740 | | | |---------------------+-------+-------+--------+---------+---------+---------| -| quickSortMiddle() | 0.096 | 0.374 | 1.558 | 5.665 | | | -| quickSortMedian() | 0.118 | 0.429 | 1.711 | 5.863 | | | -| quickSortMdnSwppd() | 0.091 | 0.334 | 1.399 | 4.893 | | | +| quickSortMiddle() | 0.096 | 0.368 | 1.568 | 5.651 | | | +| quickSortMedian() | 0.117 | 0.431 | 1.717 | 5.905 | | | +| quickSortMdnSwppd() | 0.094 | 0.341 | 1.417 | 4.909 | | | |---------------------+-------+-------+--------+---------+---------+---------| -| qsort() | 0.203 | 0.863 | 3.663 | 13.016 | | | +| qsort() | 0.204 | 0.855 | 3.629 | 13.021 | | | +---------------------+-------+-------+--------+---------+---------+---------+ ``` @@ -393,23 +419,24 @@ Here are 2 samples. | \ N | 10 | 30 | 100 | 300 | 1000 | 3000 | | Function \ | | | | | | | |---------------------+-------+-------+--------+---------+---------+---------| -| bubbleSort() | 0.021 | 0.191 | 2.232 | 20.144 | 225.651 | | +| bubbleSort() | 0.021 | 0.192 | 2.231 | 20.143 | 225.651 | | | insertionSort() | 0.009 | 0.037 | 0.362 | 3.220 | 34.646 | | +| selectionSort() | 0.017 | 0.085 | 0.892 | 7.930 | 87.723 | | |---------------------+-------+-------+--------+---------+---------+---------| -| shellSortClassic() | 0.013 | 0.050 | 0.246 | 1.020 | 4.402 | 16.259 | -| shellSortKnuth() | 0.010 | 0.036 | 0.173 | 0.691 | 3.016 | 11.270 | -| shellSortTokuda() | 0.009 | 0.038 | 0.181 | 0.730 | 3.141 | 11.368 | +| shellSortClassic() | 0.011 | 0.039 | 0.215 | 0.878 | 3.609 | 13.789 | +| shellSortKnuth() | 0.010 | 0.036 | 0.172 | 0.690 | 3.022 | 11.304 | +| shellSortTokuda() | 0.009 | 0.039 | 0.183 | 0.735 | 3.140 | 11.366 | |---------------------+-------+-------+--------+---------+---------+---------| -| combSort13() | 0.013 | 0.049 | 0.229 | 0.836 | 3.810 | 13.769 | -| combSort13m() | 0.013 | 0.051 | 0.225 | 0.842 | 3.621 | 13.130 | -| combSort133() | 0.010 | 0.040 | 0.210 | 0.804 | 3.603 | 12.406 | -| combSort133m() | 0.010 | 0.044 | 0.205 | 0.803 | 3.448 | 12.407 | +| combSort13() | 0.013 | 0.048 | 0.219 | 0.846 | 3.711 | 13.689 | +| combSort13m() | 0.014 | 0.051 | 0.222 | 0.840 | 3.622 | 13.104 | +| combSort133() | 0.010 | 0.040 | 0.208 | 0.796 | 3.571 | 12.430 | +| combSort133m() | 0.010 | 0.044 | 0.206 | 0.793 | 3.465 | 12.387 | |---------------------+-------+-------+--------+---------+---------+---------| -| quickSortMiddle() | 0.013 | 0.046 | 0.186 | 0.641 | 2.470 | 8.390 | -| quickSortMedian() | 0.016 | 0.052 | 0.201 | 0.679 | 2.577 | 8.439 | -| quickSortMdnSwppd() | 0.012 | 0.039 | 0.158 | 0.550 | 2.116 | 7.180 | +| quickSortMiddle() | 0.013 | 0.045 | 0.185 | 0.651 | 2.519 | 8.307 | +| quickSortMedian() | 0.016 | 0.052 | 0.200 | 0.677 | 2.551 | 8.403 | +| quickSortMdnSwppd() | 0.012 | 0.039 | 0.159 | 0.558 | 2.122 | 7.109 | |---------------------+-------+-------+--------+---------+---------+---------| -| qsort() | 0.027 | 0.092 | 0.414 | 1.501 | 6.002 | 20.681 | +| qsort() | 0.028 | 0.092 | 0.416 | 1.516 | 6.010 | 20.789 | +---------------------+-------+-------+--------+---------+---------+---------+ ``` diff --git a/library.properties b/library.properties index a335446..874d71d 100644 --- a/library.properties +++ b/library.properties @@ -3,7 +3,7 @@ version=0.1.0 author=Brian T. Park maintainer=Brian T. Park sentence=Various sorting algorithms for Arduino. -paragraph=Bubble Sort, Insertion Sort, Shell Sort, Comb Sort, Quick Sort. +paragraph=Bubble Sort, Insertion Sort, Selection Sort, Shell Sort, Comb Sort, Quick Sort. category=Data Processing url=https://github.com/bxparks/AceSorting architectures=* diff --git a/src/AceSorting.h b/src/AceSorting.h index 9fb91ca..f5c6445 100644 --- a/src/AceSorting.h +++ b/src/AceSorting.h @@ -49,6 +49,7 @@ SOFTWARE. #include "ace_sorting/swap.h" #include "ace_sorting/bubbleSort.h" #include "ace_sorting/insertionSort.h" +#include "ace_sorting/selectionSort.h" #include "ace_sorting/shellSort.h" #include "ace_sorting/combSort.h" #include "ace_sorting/quickSort.h" diff --git a/src/ace_sorting/selectionSort.h b/src/ace_sorting/selectionSort.h new file mode 100644 index 0000000..a96f716 --- /dev/null +++ b/src/ace_sorting/selectionSort.h @@ -0,0 +1,65 @@ +/* +MIT License + +Copyright (c) 2021 Brian T. Park + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +/** + * @file selectionSort.h + * + * Selection sort. + */ + +#ifndef ACE_SORTING_SELECTION_SORT_H +#define ACE_SORTING_SELECTION_SORT_H + +#include "swap.h" + +namespace ace_sorting { + +/** + * Selection sort. + * Average complexity: O(n^2) + * + * @tparam T type of data to sort + */ +template +void selectionSort(T data[], uint16_t n) { + for (uint16_t i = 0; i < n; i++) { + // Find the smallest element + uint16_t iSmallest = i; + T smallest = data[i]; + for (uint16_t j = i + 1; j < n; j++) { + if (data[j] < smallest) { + iSmallest = j; + smallest = data[j]; + } + } + + if (i != iSmallest) { + swap(data[i], data[iSmallest]); + } + } +} + +} + +#endif diff --git a/src/ace_sorting/shellSort.h b/src/ace_sorting/shellSort.h index 2c90939..7ee241c 100644 --- a/src/ace_sorting/shellSort.h +++ b/src/ace_sorting/shellSort.h @@ -46,7 +46,7 @@ template void shellSortClassic(T data[], uint16_t n) { uint16_t gap = n; while (gap > 1) { - gap = (gap + 1) / 2; + gap /= 2; // Do insertion sort of each sub-array separated by gap. for (uint16_t i = gap; i < n; i++) { diff --git a/tests/SortingTest/SortingTest.ino b/tests/SortingTest/SortingTest.ino index c81609e..0102125 100644 --- a/tests/SortingTest/SortingTest.ino +++ b/tests/SortingTest/SortingTest.ino @@ -10,6 +10,7 @@ using aunit::TestOnce; using ace_common::isSorted; using ace_sorting::bubbleSort; using ace_sorting::insertionSort; +using ace_sorting::selectionSort; using ace_sorting::shellSortClassic; using ace_sorting::shellSortKnuth; using ace_sorting::shellSortTokuda; @@ -100,6 +101,10 @@ testF(SortingTest, bubbleSort) { assertSort(bubbleSort); } +testF(SortingTest, selectionSort) { + assertSort(selectionSort); +} + testF(SortingTest, insertionSort) { assertSort(insertionSort); } From fb700a7688cd996b582ce78b15e519569829013c Mon Sep 17 00:00:00 2001 From: Brian Park Date: Thu, 5 Aug 2021 13:11:02 -0700 Subject: [PATCH 02/12] MemoryBenchmark: Add Selection Sort --- examples/MemoryBenchmark/MemoryBenchmark.ino | 26 +++++++++++--------- examples/MemoryBenchmark/README.md | 24 ++++++++++-------- examples/MemoryBenchmark/collect.sh | 2 +- examples/MemoryBenchmark/esp32.txt | 23 ++++++++--------- examples/MemoryBenchmark/esp8266.txt | 23 ++++++++--------- examples/MemoryBenchmark/generate_readme.py | 3 --- examples/MemoryBenchmark/generate_table.awk | 23 ++++++++--------- examples/MemoryBenchmark/micro.txt | 23 ++++++++--------- examples/MemoryBenchmark/nano.txt | 23 ++++++++--------- examples/MemoryBenchmark/samd.txt | 23 ++++++++--------- examples/MemoryBenchmark/stm32.txt | 23 ++++++++--------- examples/MemoryBenchmark/teensy32.txt | 23 ++++++++--------- 12 files changed, 126 insertions(+), 113 deletions(-) diff --git a/examples/MemoryBenchmark/MemoryBenchmark.ino b/examples/MemoryBenchmark/MemoryBenchmark.ino index b3f2a7a..218f6f8 100644 --- a/examples/MemoryBenchmark/MemoryBenchmark.ino +++ b/examples/MemoryBenchmark/MemoryBenchmark.ino @@ -9,6 +9,7 @@ using ace_sorting::bubbleSort; using ace_sorting::insertionSort; +using ace_sorting::selectionSort; using ace_sorting::shellSortClassic; using ace_sorting::shellSortKnuth; using ace_sorting::shellSortTokuda; @@ -24,17 +25,18 @@ using ace_sorting::quickSortMedianSwapped; #define FEATURE_BASELINE 0 #define FEATURE_BUBBLE_SORT 1 #define FEATURE_INSERTION_SORT 2 -#define FEATURE_SHELL_SORT_CLASSIC 3 -#define FEATURE_SHELL_SORT_KNUTH 4 -#define FEATURE_SHELL_SORT_TOKUDA 5 -#define FEATURE_COMB_SORT_13 6 -#define FEATURE_COMB_SORT_13M 7 -#define FEATURE_COMB_SORT_133 8 -#define FEATURE_COMB_SORT_133M 9 -#define FEATURE_QUICK_SORT_MIDDLE 10 -#define FEATURE_QUICK_SORT_MEDIAN 11 -#define FEATURE_QUICK_SORT_MEDIAN_SWAPPED 12 -#define FEATURE_QSORT 13 +#define FEATURE_SELECTION_SORT 3 +#define FEATURE_SHELL_SORT_CLASSIC 4 +#define FEATURE_SHELL_SORT_KNUTH 5 +#define FEATURE_SHELL_SORT_TOKUDA 6 +#define FEATURE_COMB_SORT_13 7 +#define FEATURE_COMB_SORT_13M 8 +#define FEATURE_COMB_SORT_133 9 +#define FEATURE_COMB_SORT_133M 10 +#define FEATURE_QUICK_SORT_MIDDLE 11 +#define FEATURE_QUICK_SORT_MEDIAN 12 +#define FEATURE_QUICK_SORT_MEDIAN_SWAPPED 13 +#define FEATURE_QSORT 14 // Select one of the FEATURE_* parameter and compile. Then look at the flash // and RAM usage, compared to FEATURE_BASELINE usage to determine how much @@ -78,6 +80,8 @@ void setup() { bubbleSort(data, DATA_SIZE); #elif FEATURE == FEATURE_INSERTION_SORT insertionSort(data, DATA_SIZE); +#elif FEATURE == FEATURE_SELECTION_SORT + selectionSort(data, DATA_SIZE); #elif FEATURE == FEATURE_SHELL_SORT_CLASSIC shellSortClassic(data, DATA_SIZE); #elif FEATURE == FEATURE_SHELL_SORT_KNUTH diff --git a/examples/MemoryBenchmark/README.md b/examples/MemoryBenchmark/README.md index cf3acb0..47eff8c 100644 --- a/examples/MemoryBenchmark/README.md +++ b/examples/MemoryBenchmark/README.md @@ -53,8 +53,9 @@ ASCII table. |----------------------------------------+--------------+-------------| | bubbleSort() | 1110/ 214 | 44/ 0 | | insertionSort() | 1126/ 214 | 60/ 0 | +| selectionSort() | 1166/ 214 | 100/ 0 | |----------------------------------------+--------------+-------------| -| shellSortClassic() | 1164/ 214 | 98/ 0 | +| shellSortClassic() | 1162/ 214 | 96/ 0 | | shellSortKnuth() | 1208/ 214 | 142/ 0 | | shellSortTokuda() | 1248/ 240 | 182/ 26 | |----------------------------------------+--------------+-------------| @@ -86,8 +87,9 @@ ASCII table. |----------------------------------------+--------------+-------------| | bubbleSort() | 4104/ 354 | 44/ 0 | | insertionSort() | 4120/ 354 | 60/ 0 | +| selectionSort() | 4160/ 354 | 100/ 0 | |----------------------------------------+--------------+-------------| -| shellSortClassic() | 4158/ 354 | 98/ 0 | +| shellSortClassic() | 4156/ 354 | 96/ 0 | | shellSortKnuth() | 4202/ 354 | 142/ 0 | | shellSortTokuda() | 4242/ 380 | 182/ 26 | |----------------------------------------+--------------+-------------| @@ -119,8 +121,9 @@ ASCII table. |----------------------------------------+--------------+-------------| | bubbleSort() | 10696/ 0 | 32/ 0 | | insertionSort() | 10712/ 0 | 48/ 0 | +| selectionSort() | 10744/ 0 | 80/ 0 | |----------------------------------------+--------------+-------------| -| shellSortClassic() | 10728/ 0 | 64/ 0 | +| shellSortClassic() | 10720/ 0 | 56/ 0 | | shellSortKnuth() | 10736/ 0 | 72/ 0 | | shellSortTokuda() | 10836/ 0 | 172/ 0 | |----------------------------------------+--------------+-------------| @@ -154,8 +157,9 @@ ASCII table. |----------------------------------------+--------------+-------------| | bubbleSort() | 26856/ 3844 | 36/ 0 | | insertionSort() | 26864/ 3844 | 44/ 0 | +| selectionSort() | 26884/ 3844 | 64/ 0 | |----------------------------------------+--------------+-------------| -| shellSortClassic() | 26896/ 3844 | 76/ 0 | +| shellSortClassic() | 26884/ 3844 | 64/ 0 | | shellSortKnuth() | 26900/ 3844 | 80/ 0 | | shellSortTokuda() | 26956/ 3844 | 136/ 0 | |----------------------------------------+--------------+-------------| @@ -173,9 +177,6 @@ ASCII table. ``` -An entry of `-1` indicates that the memory usage exceeded the maximum of the -microcontroller and the compiler did not generate the desired information. - ## ESP8266 * NodeMCU 1.0, 80MHz ESP8266 @@ -190,8 +191,9 @@ microcontroller and the compiler did not generate the desired information. |----------------------------------------+--------------+-------------| | bubbleSort() | 257164/26976 | 64/ 0 | | insertionSort() | 257164/26976 | 64/ 0 | +| selectionSort() | 257180/26976 | 80/ 0 | |----------------------------------------+--------------+-------------| -| shellSortClassic() | 257196/26976 | 96/ 0 | +| shellSortClassic() | 257180/26976 | 80/ 0 | | shellSortKnuth() | 257212/26976 | 112/ 0 | | shellSortTokuda() | 257256/27004 | 156/ 28 | |----------------------------------------+--------------+-------------| @@ -223,8 +225,9 @@ microcontroller and the compiler did not generate the desired information. |----------------------------------------+--------------+-------------| | bubbleSort() | 198040/13284 | 44/ 0 | | insertionSort() | 198072/13284 | 76/ 0 | +| selectionSort() | 198072/13284 | 76/ 0 | |----------------------------------------+--------------+-------------| -| shellSortClassic() | 198080/13284 | 84/ 0 | +| shellSortClassic() | 198072/13284 | 76/ 0 | | shellSortKnuth() | 198084/13284 | 88/ 0 | | shellSortTokuda() | 198152/13284 | 156/ 0 | |----------------------------------------+--------------+-------------| @@ -260,8 +263,9 @@ usage by objects. |----------------------------------------+--------------+-------------| | bubbleSort() | 7816/ 3256 | 28/ 0 | | insertionSort() | 7844/ 3256 | 56/ 0 | +| selectionSort() | 7864/ 3256 | 76/ 0 | |----------------------------------------+--------------+-------------| -| shellSortClassic() | 7876/ 3256 | 88/ 0 | +| shellSortClassic() | 7868/ 3256 | 80/ 0 | | shellSortKnuth() | 7880/ 3256 | 92/ 0 | | shellSortTokuda() | 7976/ 3256 | 188/ 0 | |----------------------------------------+--------------+-------------| diff --git a/examples/MemoryBenchmark/collect.sh b/examples/MemoryBenchmark/collect.sh index 308a1f8..345cfa3 100755 --- a/examples/MemoryBenchmark/collect.sh +++ b/examples/MemoryBenchmark/collect.sh @@ -16,7 +16,7 @@ set -eu PROGRAM_NAME='MemoryBenchmark.ino' -NUM_FEATURES=13 # excluding Baseline +NUM_FEATURES=14 # excluding Baseline # Assume that https://github.com/bxparks/AUniter is installed as a # sibling project to AceCommon. diff --git a/examples/MemoryBenchmark/esp32.txt b/examples/MemoryBenchmark/esp32.txt index 53b4fb0..0343ec6 100644 --- a/examples/MemoryBenchmark/esp32.txt +++ b/examples/MemoryBenchmark/esp32.txt @@ -1,14 +1,15 @@ 0 197996 1310720 13284 327680 1 198040 1310720 13284 327680 2 198072 1310720 13284 327680 -3 198080 1310720 13284 327680 -4 198084 1310720 13284 327680 -5 198152 1310720 13284 327680 -6 198100 1310720 13284 327680 -7 198112 1310720 13284 327680 -8 198080 1310720 13284 327680 -9 198092 1310720 13284 327680 -10 198112 1310720 13284 327680 -11 198140 1310720 13284 327680 -12 198172 1310720 13284 327680 -13 198088 1310720 13284 327680 +3 198072 1310720 13284 327680 +4 198072 1310720 13284 327680 +5 198084 1310720 13284 327680 +6 198152 1310720 13284 327680 +7 198100 1310720 13284 327680 +8 198112 1310720 13284 327680 +9 198080 1310720 13284 327680 +10 198092 1310720 13284 327680 +11 198112 1310720 13284 327680 +12 198140 1310720 13284 327680 +13 198172 1310720 13284 327680 +14 198088 1310720 13284 327680 diff --git a/examples/MemoryBenchmark/esp8266.txt b/examples/MemoryBenchmark/esp8266.txt index 9e7593f..20aad2b 100644 --- a/examples/MemoryBenchmark/esp8266.txt +++ b/examples/MemoryBenchmark/esp8266.txt @@ -1,14 +1,15 @@ 0 257100 1044464 26976 81920 1 257164 1044464 26976 81920 2 257164 1044464 26976 81920 -3 257196 1044464 26976 81920 -4 257212 1044464 26976 81920 -5 257256 1044464 27004 81920 -6 257196 1044464 26976 81920 -7 257212 1044464 26976 81920 -8 257180 1044464 26976 81920 -9 257196 1044464 26976 81920 -10 257244 1044464 26976 81920 -11 257276 1044464 26976 81920 -12 257308 1044464 26976 81920 -13 258076 1044464 26976 81920 +3 257180 1044464 26976 81920 +4 257180 1044464 26976 81920 +5 257212 1044464 26976 81920 +6 257256 1044464 27004 81920 +7 257196 1044464 26976 81920 +8 257212 1044464 26976 81920 +9 257180 1044464 26976 81920 +10 257196 1044464 26976 81920 +11 257244 1044464 26976 81920 +12 257276 1044464 26976 81920 +13 257308 1044464 26976 81920 +14 258076 1044464 26976 81920 diff --git a/examples/MemoryBenchmark/generate_readme.py b/examples/MemoryBenchmark/generate_readme.py index afdcc3e..7049952 100755 --- a/examples/MemoryBenchmark/generate_readme.py +++ b/examples/MemoryBenchmark/generate_readme.py @@ -105,9 +105,6 @@ {stm32_results} ``` -An entry of `-1` indicates that the memory usage exceeded the maximum of the -microcontroller and the compiler did not generate the desired information. - ## ESP8266 * NodeMCU 1.0, 80MHz ESP8266 diff --git a/examples/MemoryBenchmark/generate_table.awk b/examples/MemoryBenchmark/generate_table.awk index d88d0f8..12bffd1 100755 --- a/examples/MemoryBenchmark/generate_table.awk +++ b/examples/MemoryBenchmark/generate_table.awk @@ -9,17 +9,18 @@ BEGIN { labels[0] = "Baseline" labels[1] = "bubbleSort()" labels[2] = "insertionSort()" - labels[3] = "shellSortClassic()" - labels[4] = "shellSortKnuth()" - labels[5] = "shellSortTokuda()" - labels[6] = "combSort13()" - labels[7] = "combSort13m()" - labels[8] = "combSort133()" - labels[9] = "combSort133m()" - labels[10] = "quickSortMiddle()" - labels[11] = "quickSortMedian()" - labels[12] = "quickSortMedianSwapped()" - labels[13] = "qsort()" + labels[3] = "selectionSort()" + labels[4] = "shellSortClassic()" + labels[5] = "shellSortKnuth()" + labels[6] = "shellSortTokuda()" + labels[7] = "combSort13()" + labels[8] = "combSort13m()" + labels[9] = "combSort133()" + labels[10] = "combSort133m()" + labels[11] = "quickSortMiddle()" + labels[12] = "quickSortMedian()" + labels[13] = "quickSortMedianSwapped()" + labels[14] = "qsort()" record_index = 0 } { diff --git a/examples/MemoryBenchmark/micro.txt b/examples/MemoryBenchmark/micro.txt index b1e59b6..77378a2 100644 --- a/examples/MemoryBenchmark/micro.txt +++ b/examples/MemoryBenchmark/micro.txt @@ -1,14 +1,15 @@ 0 4060 28672 354 2560 1 4104 28672 354 2560 2 4120 28672 354 2560 -3 4158 28672 354 2560 -4 4202 28672 354 2560 -5 4242 28672 380 2560 -6 4214 28672 354 2560 -7 4232 28672 354 2560 -8 4166 28672 354 2560 -9 4188 28672 354 2560 -10 4238 28672 354 2560 -11 4290 28672 354 2560 -12 4338 28672 354 2560 -13 5144 28672 354 2560 +3 4160 28672 354 2560 +4 4156 28672 354 2560 +5 4202 28672 354 2560 +6 4242 28672 380 2560 +7 4214 28672 354 2560 +8 4232 28672 354 2560 +9 4166 28672 354 2560 +10 4188 28672 354 2560 +11 4238 28672 354 2560 +12 4290 28672 354 2560 +13 4338 28672 354 2560 +14 5144 28672 354 2560 diff --git a/examples/MemoryBenchmark/nano.txt b/examples/MemoryBenchmark/nano.txt index f76a49d..4dc5bd4 100644 --- a/examples/MemoryBenchmark/nano.txt +++ b/examples/MemoryBenchmark/nano.txt @@ -1,14 +1,15 @@ 0 1066 30720 214 2048 1 1110 30720 214 2048 2 1126 30720 214 2048 -3 1164 30720 214 2048 -4 1208 30720 214 2048 -5 1248 30720 240 2048 -6 1220 30720 214 2048 -7 1238 30720 214 2048 -8 1172 30720 214 2048 -9 1194 30720 214 2048 -10 1244 30720 214 2048 -11 1296 30720 214 2048 -12 1344 30720 214 2048 -13 2150 30720 214 2048 +3 1166 30720 214 2048 +4 1162 30720 214 2048 +5 1208 30720 214 2048 +6 1248 30720 240 2048 +7 1220 30720 214 2048 +8 1238 30720 214 2048 +9 1172 30720 214 2048 +10 1194 30720 214 2048 +11 1244 30720 214 2048 +12 1296 30720 214 2048 +13 1344 30720 214 2048 +14 2150 30720 214 2048 diff --git a/examples/MemoryBenchmark/samd.txt b/examples/MemoryBenchmark/samd.txt index cd7c2fc..bb07d2a 100644 --- a/examples/MemoryBenchmark/samd.txt +++ b/examples/MemoryBenchmark/samd.txt @@ -1,14 +1,15 @@ 0 10664 262144 1 10696 262144 2 10712 262144 -3 10728 262144 -4 10736 262144 -5 10836 262144 -6 10724 262144 -7 10740 262144 -8 10716 262144 -9 10740 262144 -10 10764 262144 -11 10796 262144 -12 10808 262144 -13 11448 262144 +3 10744 262144 +4 10720 262144 +5 10736 262144 +6 10836 262144 +7 10724 262144 +8 10740 262144 +9 10716 262144 +10 10740 262144 +11 10764 262144 +12 10796 262144 +13 10808 262144 +14 11448 262144 diff --git a/examples/MemoryBenchmark/stm32.txt b/examples/MemoryBenchmark/stm32.txt index 2a8f595..ae54955 100644 --- a/examples/MemoryBenchmark/stm32.txt +++ b/examples/MemoryBenchmark/stm32.txt @@ -1,14 +1,15 @@ 0 26820 131072 3844 20480 1 26856 131072 3844 20480 2 26864 131072 3844 20480 -3 26896 131072 3844 20480 -4 26900 131072 3844 20480 -5 26956 131072 3844 20480 -6 26896 131072 3844 20480 -7 26904 131072 3844 20480 -8 26888 131072 3844 20480 -9 26896 131072 3844 20480 -10 26920 131072 3844 20480 -11 26952 131072 3844 20480 -12 26976 131072 3844 20480 -13 27652 131072 3844 20480 +3 26884 131072 3844 20480 +4 26884 131072 3844 20480 +5 26900 131072 3844 20480 +6 26956 131072 3844 20480 +7 26896 131072 3844 20480 +8 26904 131072 3844 20480 +9 26888 131072 3844 20480 +10 26896 131072 3844 20480 +11 26920 131072 3844 20480 +12 26952 131072 3844 20480 +13 26976 131072 3844 20480 +14 27652 131072 3844 20480 diff --git a/examples/MemoryBenchmark/teensy32.txt b/examples/MemoryBenchmark/teensy32.txt index b935eb0..57c4508 100644 --- a/examples/MemoryBenchmark/teensy32.txt +++ b/examples/MemoryBenchmark/teensy32.txt @@ -1,14 +1,15 @@ 0 7788 262144 3256 65536 1 7816 262144 3256 65536 2 7844 262144 3256 65536 -3 7876 262144 3256 65536 -4 7880 262144 3256 65536 -5 7976 262144 3256 65536 -6 7864 262144 3256 65536 -7 7876 262144 3256 65536 -8 7844 262144 3256 65536 -9 7860 262144 3256 65536 -10 7896 262144 3256 65536 -11 7932 262144 3256 65536 -12 7960 262144 3256 65536 -13 9248 262144 3256 65536 +3 7864 262144 3256 65536 +4 7868 262144 3256 65536 +5 7880 262144 3256 65536 +6 7976 262144 3256 65536 +7 7864 262144 3256 65536 +8 7876 262144 3256 65536 +9 7844 262144 3256 65536 +10 7860 262144 3256 65536 +11 7896 262144 3256 65536 +12 7932 262144 3256 65536 +13 7960 262144 3256 65536 +14 9248 262144 3256 65536 From 2349ba4bdb22b678d7cd1daf0b79bd9d2347e5de Mon Sep 17 00:00:00 2001 From: Brian Park Date: Thu, 5 Aug 2021 13:11:45 -0700 Subject: [PATCH 03/12] WorstCaseBenchmark: Add Selection Sort --- examples/WorstCaseBenchmark/Benchmark.cpp | 2 + examples/WorstCaseBenchmark/README.md | 185 +++++++++++----------- examples/WorstCaseBenchmark/esp32.txt | 27 ++-- examples/WorstCaseBenchmark/esp8266.txt | 27 ++-- examples/WorstCaseBenchmark/micro.txt | 27 ++-- examples/WorstCaseBenchmark/nano.txt | 23 +-- examples/WorstCaseBenchmark/samd.txt | 27 ++-- examples/WorstCaseBenchmark/stm32.txt | 27 ++-- examples/WorstCaseBenchmark/teensy32.txt | 27 ++-- 9 files changed, 194 insertions(+), 178 deletions(-) diff --git a/examples/WorstCaseBenchmark/Benchmark.cpp b/examples/WorstCaseBenchmark/Benchmark.cpp index a752a4d..1b1b8fc 100644 --- a/examples/WorstCaseBenchmark/Benchmark.cpp +++ b/examples/WorstCaseBenchmark/Benchmark.cpp @@ -26,6 +26,7 @@ using ace_common::isSorted; using ace_common::reverse; using ace_sorting::bubbleSort; using ace_sorting::insertionSort; +using ace_sorting::selectionSort; using ace_sorting::shellSortClassic; using ace_sorting::shellSortKnuth; using ace_sorting::shellSortTokuda; @@ -191,6 +192,7 @@ void runBenchmarks() { runSort(F("bubbleSort()"), SLOW_SAMPLE_SIZE, bubbleSort); #endif runSort(F("insertionSort()"), SLOW_SAMPLE_SIZE, insertionSort); + runSort(F("selectionSort()"), SLOW_SAMPLE_SIZE, selectionSort); runSort( F("shellSortClassic()"), FAST_SAMPLE_SIZE, shellSortClassic); diff --git a/examples/WorstCaseBenchmark/README.md b/examples/WorstCaseBenchmark/README.md index ffed41d..7a32f72 100644 --- a/examples/WorstCaseBenchmark/README.md +++ b/examples/WorstCaseBenchmark/README.md @@ -80,21 +80,22 @@ when sorting different sized arrays. |-----------------------------+------+---------+---------+----------| | bubbleSort() | 300 | 118.835 | 0.360 | 141.205 | | insertionSort() | 300 | 21.685 | 0.585 | 42.715 | +| selectionSort() | 300 | 48.884 | 48.453 | 50.044 | |-----------------------------+------+---------+---------+----------| -| shellSortClassic() | 300 | 7.422 | 5.445 | 6.546 | -| shellSortKnuth() | 300 | 5.746 | 3.084 | 4.132 | -| shellSortTokuda() | 300 | 6.500 | 4.474 | 5.498 | +| shellSortClassic() | 300 | 6.906 | 4.780 | 5.987 | +| shellSortKnuth() | 300 | 5.732 | 3.084 | 4.132 | +| shellSortTokuda() | 300 | 6.558 | 4.474 | 5.496 | |-----------------------------+------+---------+---------+----------| -| combSort13() | 300 | 8.188 | 6.408 | 7.241 | -| combSort13m() | 300 | 8.307 | 6.414 | 7.248 | -| combSort133() | 300 | 7.679 | 5.886 | 6.714 | -| combSort133m() | 300 | 7.748 | 5.892 | 6.721 | +| combSort13() | 300 | 8.160 | 6.409 | 7.242 | +| combSort13m() | 300 | 8.162 | 6.414 | 7.248 | +| combSort133() | 300 | 7.671 | 5.882 | 6.714 | +| combSort133m() | 300 | 7.545 | 5.890 | 6.720 | |-----------------------------+------+---------+---------+----------| -| quickSortMiddle() | 300 | 5.523 | 4.084 | 4.019 | -| quickSortMedian() | 300 | 5.807 | 4.489 | 4.412 | -| quickSortMedianSwapped() | 300 | 4.870 | 3.968 | 3.926 | +| quickSortMiddle() | 300 | 5.648 | 4.090 | 4.018 | +| quickSortMedian() | 300 | 5.888 | 4.485 | 4.414 | +| quickSortMedianSwapped() | 300 | 4.875 | 3.968 | 3.932 | |-----------------------------+------+---------+---------+----------| -| qsort() | 300 | 12.952 | 3.987 | 5.558 | +| qsort() | 300 | 12.926 | 3.987 | 5.558 | +-----------------------------+------+---------+---------+----------+ ``` @@ -110,23 +111,24 @@ when sorting different sized arrays. +-----------------------------+------+---------+---------+----------+ | Function | N | random | sorted | reversed | |-----------------------------+------+---------+---------+----------| -| bubbleSort() | 300 | 119.311 | 0.364 | 141.933 | -| insertionSort() | 300 | 21.628 | 0.592 | 42.936 | +| bubbleSort() | 300 | 119.305 | 0.365 | 141.935 | +| insertionSort() | 300 | 21.625 | 0.589 | 42.940 | +| selectionSort() | 300 | 49.151 | 48.709 | 50.303 | |-----------------------------+------+---------+---------+----------| -| shellSortClassic() | 300 | 7.468 | 5.473 | 6.580 | -| shellSortKnuth() | 300 | 5.627 | 3.101 | 4.154 | -| shellSortTokuda() | 300 | 6.545 | 4.497 | 5.525 | +| shellSortClassic() | 300 | 6.960 | 4.803 | 6.017 | +| shellSortKnuth() | 300 | 5.713 | 3.100 | 4.154 | +| shellSortTokuda() | 300 | 6.562 | 4.498 | 5.527 | |-----------------------------+------+---------+---------+----------| -| combSort13() | 300 | 8.103 | 6.442 | 7.278 | -| combSort13m() | 300 | 8.167 | 6.448 | 7.285 | -| combSort133() | 300 | 7.673 | 5.916 | 6.746 | -| combSort133m() | 300 | 7.889 | 5.920 | 6.755 | +| combSort13() | 300 | 8.109 | 6.443 | 7.280 | +| combSort13m() | 300 | 8.204 | 6.448 | 7.288 | +| combSort133() | 300 | 7.752 | 5.916 | 6.750 | +| combSort133m() | 300 | 7.700 | 5.921 | 6.754 | |-----------------------------+------+---------+---------+----------| -| quickSortMiddle() | 300 | 5.580 | 4.106 | 4.041 | -| quickSortMedian() | 300 | 5.939 | 4.509 | 4.435 | -| quickSortMedianSwapped() | 300 | 4.972 | 3.992 | 3.949 | +| quickSortMiddle() | 300 | 5.803 | 4.107 | 4.038 | +| quickSortMedian() | 300 | 5.864 | 4.508 | 4.436 | +| quickSortMedianSwapped() | 300 | 4.949 | 3.990 | 3.952 | |-----------------------------+------+---------+---------+----------| -| qsort() | 300 | 13.055 | 4.006 | 5.585 | +| qsort() | 300 | 13.084 | 4.006 | 5.587 | +-----------------------------+------+---------+---------+----------+ ``` @@ -141,23 +143,24 @@ when sorting different sized arrays. +-----------------------------+------+---------+---------+----------+ | Function | N | random | sorted | reversed | |-----------------------------+------+---------+---------+----------| -| bubbleSort() | 1000 | 417.697 | 0.422 | 460.605 | -| insertionSort() | 1000 | 90.435 | 0.505 | 178.236 | +| bubbleSort() | 1000 | 428.877 | 0.422 | 460.607 | +| insertionSort() | 1000 | 89.600 | 0.504 | 178.246 | +| selectionSort() | 1000 | 157.524 | 157.464 | 152.365 | |-----------------------------+------+---------+---------+----------| -| shellSortClassic() | 1000 | 7.518 | 4.530 | 5.809 | -| shellSortKnuth() | 1000 | 5.142 | 2.537 | 3.581 | -| shellSortTokuda() | 1000 | 6.701 | 4.297 | 5.709 | +| shellSortClassic() | 1000 | 5.865 | 3.693 | 4.947 | +| shellSortKnuth() | 1000 | 5.114 | 2.537 | 3.580 | +| shellSortTokuda() | 1000 | 6.678 | 4.297 | 5.708 | |-----------------------------+------+---------+---------+----------| -| combSort13() | 1000 | 8.197 | 6.355 | 6.889 | -| combSort13m() | 1000 | 7.927 | 6.693 | 7.222 | -| combSort133() | 1000 | 7.896 | 6.057 | 6.593 | -| combSort133m() | 1000 | 7.622 | 6.394 | 6.932 | +| combSort13() | 1000 | 8.163 | 6.355 | 6.889 | +| combSort13m() | 1000 | 7.875 | 6.694 | 7.222 | +| combSort133() | 1000 | 7.798 | 6.057 | 6.593 | +| combSort133m() | 1000 | 7.624 | 6.394 | 6.932 | |-----------------------------+------+---------+---------+----------| -| quickSortMiddle() | 1000 | 4.190 | 2.960 | 2.910 | -| quickSortMedian() | 1000 | 4.336 | 3.201 | 3.152 | -| quickSortMedianSwapped() | 1000 | 3.758 | 3.026 | 2.975 | +| quickSortMiddle() | 1000 | 4.212 | 2.958 | 2.909 | +| quickSortMedian() | 1000 | 4.387 | 3.202 | 3.152 | +| quickSortMedianSwapped() | 1000 | 3.751 | 3.024 | 2.976 | |-----------------------------+------+---------+---------+----------| -| qsort() | 1000 | 12.309 | 3.643 | 5.029 | +| qsort() | 1000 | 11.968 | 3.518 | 4.892 | +-----------------------------+------+---------+---------+----------+ ``` @@ -172,23 +175,24 @@ when sorting different sized arrays. +-----------------------------+------+---------+---------+----------+ | Function | N | random | sorted | reversed | |-----------------------------+------+---------+---------+----------| -| bubbleSort() | 1000 | 241.144 | 0.253 | 251.281 | -| insertionSort() | 1000 | 46.976 | 0.362 | 90.948 | +| bubbleSort() | 1000 | 241.152 | 0.254 | 251.291 | +| insertionSort() | 1000 | 46.977 | 0.366 | 90.953 | +| selectionSort() | 1000 | 105.225 | 105.186 | 105.208 | |-----------------------------+------+---------+---------+----------| -| shellSortClassic() | 1000 | 6.290 | 4.024 | 5.045 | -| shellSortKnuth() | 1000 | 5.098 | 2.367 | 3.466 | -| shellSortTokuda() | 1000 | 3.908 | 2.469 | 3.256 | +| shellSortClassic() | 1000 | 5.527 | 3.245 | 4.591 | +| shellSortKnuth() | 1000 | 5.036 | 2.366 | 3.466 | +| shellSortTokuda() | 1000 | 3.928 | 2.273 | 3.189 | |-----------------------------+------+---------+---------+----------| -| combSort13() | 1000 | 8.072 | 6.804 | 7.165 | -| combSort13m() | 1000 | 7.665 | 6.891 | 7.260 | -| combSort133() | 1000 | 7.552 | 6.304 | 6.674 | -| combSort133m() | 1000 | 7.357 | 6.652 | 7.022 | +| combSort13() | 1000 | 7.861 | 6.544 | 6.913 | +| combSort13m() | 1000 | 7.395 | 6.617 | 6.971 | +| combSort133() | 1000 | 7.542 | 6.304 | 6.653 | +| combSort133m() | 1000 | 7.067 | 6.387 | 6.743 | |-----------------------------+------+---------+---------+----------| -| quickSortMiddle() | 1000 | 3.919 | 2.796 | 2.762 | -| quickSortMedian() | 1000 | 4.265 | 3.315 | 3.248 | -| quickSortMedianSwapped() | 1000 | 3.248 | 2.907 | 2.797 | +| quickSortMiddle() | 1000 | 3.829 | 2.685 | 2.659 | +| quickSortMedian() | 1000 | 4.219 | 3.304 | 3.235 | +| quickSortMedianSwapped() | 1000 | 3.275 | 2.904 | 2.794 | |-----------------------------+------+---------+---------+----------| -| qsort() | 1000 | 8.280 | 2.658 | 3.592 | +| qsort() | 1000 | 8.783 | 2.664 | 3.643 | +-----------------------------+------+---------+---------+----------+ ``` @@ -203,23 +207,24 @@ when sorting different sized arrays. +-----------------------------+------+---------+---------+----------+ | Function | N | random | sorted | reversed | |-----------------------------+------+---------+---------+----------| -| bubbleSort() | 1000 | 234.792 | 0.242 | 243.619 | -| insertionSort() | 1000 | 34.031 | 0.291 | 68.866 | +| bubbleSort() | 1000 | 227.582 | 0.238 | 243.636 | +| insertionSort() | 1000 | 34.636 | 0.288 | 68.875 | +| selectionSort() | 1000 | 93.804 | 93.914 | 87.739 | |-----------------------------+------+---------+---------+----------| -| shellSortClassic() | 1000 | 4.070 | 2.703 | 3.251 | -| shellSortKnuth() | 1000 | 2.983 | 1.713 | 2.208 | -| shellSortTokuda() | 1000 | 3.143 | 2.209 | 2.742 | +| shellSortClassic() | 1000 | 3.602 | 2.506 | 3.100 | +| shellSortKnuth() | 1000 | 3.007 | 1.714 | 2.209 | +| shellSortTokuda() | 1000 | 3.142 | 2.211 | 2.741 | |-----------------------------+------+---------+---------+----------| -| combSort13() | 1000 | 3.763 | 3.072 | 3.253 | -| combSort13m() | 1000 | 3.600 | 3.234 | 3.421 | -| combSort133() | 1000 | 3.620 | 2.935 | 3.119 | -| combSort133m() | 1000 | 3.472 | 3.099 | 3.281 | +| combSort13() | 1000 | 3.765 | 3.073 | 3.253 | +| combSort13m() | 1000 | 3.622 | 3.234 | 3.417 | +| combSort133() | 1000 | 3.604 | 2.940 | 3.120 | +| combSort133m() | 1000 | 3.482 | 3.102 | 3.282 | |-----------------------------+------+---------+---------+----------| -| quickSortMiddle() | 1000 | 2.491 | 1.796 | 1.748 | -| quickSortMedian() | 1000 | 2.559 | 1.924 | 1.873 | -| quickSortMedianSwapped() | 1000 | 2.132 | 1.775 | 1.726 | +| quickSortMiddle() | 1000 | 2.496 | 1.799 | 1.749 | +| quickSortMedian() | 1000 | 2.570 | 1.921 | 1.874 | +| quickSortMedianSwapped() | 1000 | 2.125 | 1.777 | 1.728 | |-----------------------------+------+---------+---------+----------| -| qsort() | 1000 | 6.019 | 1.635 | 2.321 | +| qsort() | 1000 | 6.026 | 1.632 | 2.320 | +-----------------------------+------+---------+---------+----------+ ``` @@ -234,23 +239,24 @@ when sorting different sized arrays. +-----------------------------+------+---------+---------+----------+ | Function | N | random | sorted | reversed | |-----------------------------+------+---------+---------+----------| -| bubbleSort() | 1000 | 64.709 | 0.068 | 67.146 | -| insertionSort() | 1000 | 14.837 | 0.092 | 29.422 | +| bubbleSort() | 1000 | 65.067 | 0.067 | 67.146 | +| insertionSort() | 1000 | 15.068 | 0.092 | 29.422 | +| selectionSort() | 1000 | 33.620 | 33.620 | 32.592 | |-----------------------------+------+---------+---------+----------| -| shellSortClassic() | 1000 | 1.446 | 0.871 | 1.117 | -| shellSortKnuth() | 1000 | 1.108 | 0.551 | 0.777 | -| shellSortTokuda() | 1000 | 1.119 | 0.684 | 0.942 | +| shellSortClassic() | 1000 | 1.267 | 0.774 | 1.065 | +| shellSortKnuth() | 1000 | 1.102 | 0.552 | 0.778 | +| shellSortTokuda() | 1000 | 1.112 | 0.683 | 0.942 | |-----------------------------+------+---------+---------+----------| -| combSort13() | 1000 | 1.696 | 1.416 | 1.492 | -| combSort13m() | 1000 | 1.655 | 1.493 | 1.569 | -| combSort133() | 1000 | 1.678 | 1.365 | 1.441 | -| combSort133m() | 1000 | 1.588 | 1.440 | 1.516 | +| combSort13() | 1000 | 1.750 | 1.417 | 1.492 | +| combSort13m() | 1000 | 1.644 | 1.491 | 1.568 | +| combSort133() | 1000 | 1.632 | 1.365 | 1.439 | +| combSort133m() | 1000 | 1.588 | 1.441 | 1.516 | |-----------------------------+------+---------+---------+----------| -| quickSortMiddle() | 1000 | 0.978 | 0.714 | 0.696 | -| quickSortMedian() | 1000 | 0.973 | 0.746 | 0.727 | -| quickSortMedianSwapped() | 1000 | 0.816 | 0.701 | 0.682 | +| quickSortMiddle() | 1000 | 0.990 | 0.715 | 0.697 | +| quickSortMedian() | 1000 | 0.961 | 0.745 | 0.728 | +| quickSortMedianSwapped() | 1000 | 0.834 | 0.700 | 0.681 | |-----------------------------+------+---------+---------+----------| -| qsort() | 1000 | 2.103 | 0.607 | 0.849 | +| qsort() | 1000 | 2.096 | 0.608 | 0.849 | +-----------------------------+------+---------+---------+----------+ ``` @@ -266,23 +272,24 @@ when sorting different sized arrays. +-----------------------------+------+---------+---------+----------+ | Function | N | random | sorted | reversed | |-----------------------------+------+---------+---------+----------| -| bubbleSort() | 1000 | 98.597 | 0.094 | 109.580 | -| insertionSort() | 1000 | 35.949 | 0.200 | 73.183 | +| bubbleSort() | 1000 | 98.817 | 0.095 | 109.561 | +| insertionSort() | 1000 | 36.406 | 0.199 | 73.164 | +| selectionSort() | 1000 | 57.563 | 57.511 | 57.535 | |-----------------------------+------+---------+---------+----------| -| shellSortClassic() | 1000 | 3.018 | 1.787 | 2.403 | -| shellSortKnuth() | 1000 | 2.355 | 1.085 | 1.668 | -| shellSortTokuda() | 1000 | 2.313 | 1.403 | 2.005 | +| shellSortClassic() | 1000 | 2.708 | 1.590 | 2.333 | +| shellSortKnuth() | 1000 | 2.332 | 1.084 | 1.668 | +| shellSortTokuda() | 1000 | 2.308 | 1.403 | 2.005 | |-----------------------------+------+---------+---------+----------| -| combSort13() | 1000 | 3.282 | 2.544 | 2.746 | -| combSort13m() | 1000 | 3.140 | 2.681 | 2.880 | -| combSort133() | 1000 | 3.135 | 2.451 | 2.654 | -| combSort133m() | 1000 | 3.030 | 2.587 | 2.790 | +| combSort13() | 1000 | 3.253 | 2.544 | 2.745 | +| combSort13m() | 1000 | 3.146 | 2.680 | 2.879 | +| combSort133() | 1000 | 3.128 | 2.451 | 2.653 | +| combSort133m() | 1000 | 3.057 | 2.586 | 2.789 | |-----------------------------+------+---------+---------+----------| -| quickSortMiddle() | 1000 | 1.521 | 1.137 | 1.100 | -| quickSortMedian() | 1000 | 1.594 | 1.249 | 1.208 | -| quickSortMedianSwapped() | 1000 | 1.400 | 1.203 | 1.163 | +| quickSortMiddle() | 1000 | 1.550 | 1.136 | 1.101 | +| quickSortMedian() | 1000 | 1.600 | 1.248 | 1.207 | +| quickSortMedianSwapped() | 1000 | 1.404 | 1.203 | 1.162 | |-----------------------------+------+---------+---------+----------| -| qsort() | 1000 | 4.655 | 1.111 | 1.660 | +| qsort() | 1000 | 4.598 | 1.111 | 1.646 | +-----------------------------+------+---------+---------+----------+ ``` diff --git a/examples/WorstCaseBenchmark/esp32.txt b/examples/WorstCaseBenchmark/esp32.txt index 6218fb2..c1b78ed 100644 --- a/examples/WorstCaseBenchmark/esp32.txt +++ b/examples/WorstCaseBenchmark/esp32.txt @@ -1,15 +1,16 @@ BENCHMARKS -bubbleSort() 1000 64.709 0.068 67.146 3 -insertionSort() 1000 14.837 0.092 29.422 3 -shellSortClassic() 1000 1.446 0.871 1.117 20 -shellSortKnuth() 1000 1.108 0.551 0.777 20 -shellSortTokuda() 1000 1.119 0.684 0.942 20 -combSort13() 1000 1.696 1.416 1.492 20 -combSort13m() 1000 1.655 1.493 1.569 20 -combSort133() 1000 1.678 1.365 1.441 20 -combSort133m() 1000 1.588 1.440 1.516 20 -quickSortMiddle() 1000 0.978 0.714 0.696 20 -quickSortMedian() 1000 0.973 0.746 0.727 20 -quickSortMedianSwapped() 1000 0.816 0.701 0.682 20 -qsort() 1000 2.103 0.607 0.849 20 +bubbleSort() 1000 65.067 0.067 67.146 3 +insertionSort() 1000 15.068 0.092 29.422 3 +selectionSort() 1000 33.620 33.620 32.592 3 +shellSortClassic() 1000 1.267 0.774 1.065 20 +shellSortKnuth() 1000 1.102 0.552 0.778 20 +shellSortTokuda() 1000 1.112 0.683 0.942 20 +combSort13() 1000 1.750 1.417 1.492 20 +combSort13m() 1000 1.644 1.491 1.568 20 +combSort133() 1000 1.632 1.365 1.439 20 +combSort133m() 1000 1.588 1.441 1.516 20 +quickSortMiddle() 1000 0.990 0.715 0.697 20 +quickSortMedian() 1000 0.961 0.745 0.728 20 +quickSortMedianSwapped() 1000 0.834 0.700 0.681 20 +qsort() 1000 2.096 0.608 0.849 20 END diff --git a/examples/WorstCaseBenchmark/esp8266.txt b/examples/WorstCaseBenchmark/esp8266.txt index fb0e8a1..15868f0 100644 --- a/examples/WorstCaseBenchmark/esp8266.txt +++ b/examples/WorstCaseBenchmark/esp8266.txt @@ -1,15 +1,16 @@ BENCHMARKS -bubbleSort() 1000 234.792 0.242 243.619 3 -insertionSort() 1000 34.031 0.291 68.866 3 -shellSortClassic() 1000 4.070 2.703 3.251 20 -shellSortKnuth() 1000 2.983 1.713 2.208 20 -shellSortTokuda() 1000 3.143 2.209 2.742 20 -combSort13() 1000 3.763 3.072 3.253 20 -combSort13m() 1000 3.600 3.234 3.421 20 -combSort133() 1000 3.620 2.935 3.119 20 -combSort133m() 1000 3.472 3.099 3.281 20 -quickSortMiddle() 1000 2.491 1.796 1.748 20 -quickSortMedian() 1000 2.559 1.924 1.873 20 -quickSortMedianSwapped() 1000 2.132 1.775 1.726 20 -qsort() 1000 6.019 1.635 2.321 20 +bubbleSort() 1000 227.582 0.238 243.636 3 +insertionSort() 1000 34.636 0.288 68.875 3 +selectionSort() 1000 93.804 93.914 87.739 3 +shellSortClassic() 1000 3.602 2.506 3.100 20 +shellSortKnuth() 1000 3.007 1.714 2.209 20 +shellSortTokuda() 1000 3.142 2.211 2.741 20 +combSort13() 1000 3.765 3.073 3.253 20 +combSort13m() 1000 3.622 3.234 3.417 20 +combSort133() 1000 3.604 2.940 3.120 20 +combSort133m() 1000 3.482 3.102 3.282 20 +quickSortMiddle() 1000 2.496 1.799 1.749 20 +quickSortMedian() 1000 2.570 1.921 1.874 20 +quickSortMedianSwapped() 1000 2.125 1.777 1.728 20 +qsort() 1000 6.026 1.632 2.320 20 END diff --git a/examples/WorstCaseBenchmark/micro.txt b/examples/WorstCaseBenchmark/micro.txt index 6c66f37..1af6e39 100644 --- a/examples/WorstCaseBenchmark/micro.txt +++ b/examples/WorstCaseBenchmark/micro.txt @@ -1,15 +1,16 @@ BENCHMARKS -bubbleSort() 300 119.311 0.364 141.933 3 -insertionSort() 300 21.628 0.592 42.936 3 -shellSortClassic() 300 7.468 5.473 6.580 10 -shellSortKnuth() 300 5.627 3.101 4.154 10 -shellSortTokuda() 300 6.545 4.497 5.525 10 -combSort13() 300 8.103 6.442 7.278 10 -combSort13m() 300 8.167 6.448 7.285 10 -combSort133() 300 7.673 5.916 6.746 10 -combSort133m() 300 7.889 5.920 6.755 10 -quickSortMiddle() 300 5.580 4.106 4.041 10 -quickSortMedian() 300 5.939 4.509 4.435 10 -quickSortMedianSwapped() 300 4.972 3.992 3.949 10 -qsort() 300 13.055 4.006 5.585 10 +bubbleSort() 300 119.305 0.365 141.935 3 +insertionSort() 300 21.625 0.589 42.940 3 +selectionSort() 300 49.151 48.709 50.303 3 +shellSortClassic() 300 6.960 4.803 6.017 10 +shellSortKnuth() 300 5.713 3.100 4.154 10 +shellSortTokuda() 300 6.562 4.498 5.527 10 +combSort13() 300 8.109 6.443 7.280 10 +combSort13m() 300 8.204 6.448 7.288 10 +combSort133() 300 7.752 5.916 6.750 10 +combSort133m() 300 7.700 5.921 6.754 10 +quickSortMiddle() 300 5.803 4.107 4.038 10 +quickSortMedian() 300 5.864 4.508 4.436 10 +quickSortMedianSwapped() 300 4.949 3.990 3.952 10 +qsort() 300 13.084 4.006 5.587 10 END diff --git a/examples/WorstCaseBenchmark/nano.txt b/examples/WorstCaseBenchmark/nano.txt index d7178bb..5305016 100644 --- a/examples/WorstCaseBenchmark/nano.txt +++ b/examples/WorstCaseBenchmark/nano.txt @@ -1,15 +1,16 @@ BENCHMARKS bubbleSort() 300 118.835 0.360 141.205 3 insertionSort() 300 21.685 0.585 42.715 3 -shellSortClassic() 300 7.422 5.445 6.546 10 -shellSortKnuth() 300 5.746 3.084 4.132 10 -shellSortTokuda() 300 6.500 4.474 5.498 10 -combSort13() 300 8.188 6.408 7.241 10 -combSort13m() 300 8.307 6.414 7.248 10 -combSort133() 300 7.679 5.886 6.714 10 -combSort133m() 300 7.748 5.892 6.721 10 -quickSortMiddle() 300 5.523 4.084 4.019 10 -quickSortMedian() 300 5.807 4.489 4.412 10 -quickSortMedianSwapped() 300 4.870 3.968 3.926 10 -qsort() 300 12.952 3.987 5.558 10 +selectionSort() 300 48.884 48.453 50.044 3 +shellSortClassic() 300 6.906 4.780 5.987 10 +shellSortKnuth() 300 5.732 3.084 4.132 10 +shellSortTokuda() 300 6.558 4.474 5.496 10 +combSort13() 300 8.160 6.409 7.242 10 +combSort13m() 300 8.162 6.414 7.248 10 +combSort133() 300 7.671 5.882 6.714 10 +combSort133m() 300 7.545 5.890 6.720 10 +quickSortMiddle() 300 5.648 4.090 4.018 10 +quickSortMedian() 300 5.888 4.485 4.414 10 +quickSortMedianSwapped() 300 4.875 3.968 3.932 10 +qsort() 300 12.926 3.987 5.558 10 END diff --git a/examples/WorstCaseBenchmark/samd.txt b/examples/WorstCaseBenchmark/samd.txt index c7b9705..2bc3afe 100644 --- a/examples/WorstCaseBenchmark/samd.txt +++ b/examples/WorstCaseBenchmark/samd.txt @@ -1,15 +1,16 @@ BENCHMARKS -bubbleSort() 1000 417.697 0.422 460.605 3 -insertionSort() 1000 90.435 0.505 178.236 3 -shellSortClassic() 1000 7.518 4.530 5.809 20 -shellSortKnuth() 1000 5.142 2.537 3.581 20 -shellSortTokuda() 1000 6.701 4.297 5.709 20 -combSort13() 1000 8.197 6.355 6.889 20 -combSort13m() 1000 7.927 6.693 7.222 20 -combSort133() 1000 7.896 6.057 6.593 20 -combSort133m() 1000 7.622 6.394 6.932 20 -quickSortMiddle() 1000 4.190 2.960 2.910 20 -quickSortMedian() 1000 4.336 3.201 3.152 20 -quickSortMedianSwapped() 1000 3.758 3.026 2.975 20 -qsort() 1000 12.309 3.643 5.029 20 +bubbleSort() 1000 428.877 0.422 460.607 3 +insertionSort() 1000 89.600 0.504 178.246 3 +selectionSort() 1000 157.524 157.464 152.365 3 +shellSortClassic() 1000 5.865 3.693 4.947 20 +shellSortKnuth() 1000 5.114 2.537 3.580 20 +shellSortTokuda() 1000 6.678 4.297 5.708 20 +combSort13() 1000 8.163 6.355 6.889 20 +combSort13m() 1000 7.875 6.694 7.222 20 +combSort133() 1000 7.798 6.057 6.593 20 +combSort133m() 1000 7.624 6.394 6.932 20 +quickSortMiddle() 1000 4.212 2.958 2.909 20 +quickSortMedian() 1000 4.387 3.202 3.152 20 +quickSortMedianSwapped() 1000 3.751 3.024 2.976 20 +qsort() 1000 11.968 3.518 4.892 20 END diff --git a/examples/WorstCaseBenchmark/stm32.txt b/examples/WorstCaseBenchmark/stm32.txt index 8e490e5..6e0f981 100644 --- a/examples/WorstCaseBenchmark/stm32.txt +++ b/examples/WorstCaseBenchmark/stm32.txt @@ -1,15 +1,16 @@ BENCHMARKS -bubbleSort() 1000 241.144 0.253 251.281 3 -insertionSort() 1000 46.976 0.362 90.948 3 -shellSortClassic() 1000 6.290 4.024 5.045 20 -shellSortKnuth() 1000 5.098 2.367 3.466 20 -shellSortTokuda() 1000 3.908 2.469 3.256 20 -combSort13() 1000 8.072 6.804 7.165 20 -combSort13m() 1000 7.665 6.891 7.260 20 -combSort133() 1000 7.552 6.304 6.674 20 -combSort133m() 1000 7.357 6.652 7.022 20 -quickSortMiddle() 1000 3.919 2.796 2.762 20 -quickSortMedian() 1000 4.265 3.315 3.248 20 -quickSortMedianSwapped() 1000 3.248 2.907 2.797 20 -qsort() 1000 8.280 2.658 3.592 20 +bubbleSort() 1000 241.152 0.254 251.291 3 +insertionSort() 1000 46.977 0.366 90.953 3 +selectionSort() 1000 105.225 105.186 105.208 3 +shellSortClassic() 1000 5.527 3.245 4.591 20 +shellSortKnuth() 1000 5.036 2.366 3.466 20 +shellSortTokuda() 1000 3.928 2.273 3.189 20 +combSort13() 1000 7.861 6.544 6.913 20 +combSort13m() 1000 7.395 6.617 6.971 20 +combSort133() 1000 7.542 6.304 6.653 20 +combSort133m() 1000 7.067 6.387 6.743 20 +quickSortMiddle() 1000 3.829 2.685 2.659 20 +quickSortMedian() 1000 4.219 3.304 3.235 20 +quickSortMedianSwapped() 1000 3.275 2.904 2.794 20 +qsort() 1000 8.783 2.664 3.643 20 END diff --git a/examples/WorstCaseBenchmark/teensy32.txt b/examples/WorstCaseBenchmark/teensy32.txt index f0e5726..ac84629 100644 --- a/examples/WorstCaseBenchmark/teensy32.txt +++ b/examples/WorstCaseBenchmark/teensy32.txt @@ -1,15 +1,16 @@ BENCHMARKS -bubbleSort() 1000 98.597 0.094 109.580 3 -insertionSort() 1000 35.949 0.200 73.183 3 -shellSortClassic() 1000 3.018 1.787 2.403 20 -shellSortKnuth() 1000 2.355 1.085 1.668 20 -shellSortTokuda() 1000 2.313 1.403 2.005 20 -combSort13() 1000 3.282 2.544 2.746 20 -combSort13m() 1000 3.140 2.681 2.880 20 -combSort133() 1000 3.135 2.451 2.654 20 -combSort133m() 1000 3.030 2.587 2.790 20 -quickSortMiddle() 1000 1.521 1.137 1.100 20 -quickSortMedian() 1000 1.594 1.249 1.208 20 -quickSortMedianSwapped() 1000 1.400 1.203 1.163 20 -qsort() 1000 4.655 1.111 1.660 20 +bubbleSort() 1000 98.817 0.095 109.561 3 +insertionSort() 1000 36.406 0.199 73.164 3 +selectionSort() 1000 57.563 57.511 57.535 3 +shellSortClassic() 1000 2.708 1.590 2.333 20 +shellSortKnuth() 1000 2.332 1.084 1.668 20 +shellSortTokuda() 1000 2.308 1.403 2.005 20 +combSort13() 1000 3.253 2.544 2.745 20 +combSort13m() 1000 3.146 2.680 2.879 20 +combSort133() 1000 3.128 2.451 2.653 20 +combSort133m() 1000 3.057 2.586 2.789 20 +quickSortMiddle() 1000 1.550 1.136 1.101 20 +quickSortMedian() 1000 1.600 1.248 1.207 20 +quickSortMedianSwapped() 1000 1.404 1.203 1.162 20 +qsort() 1000 4.598 1.111 1.646 20 END From 36c831bc25486e26ea3457605030d1af4a186ec1 Mon Sep 17 00:00:00 2001 From: Brian Park Date: Thu, 5 Aug 2021 13:12:41 -0700 Subject: [PATCH 04/12] AutoBenchmark: Add Selection Sort --- examples/AutoBenchmark/Benchmark.cpp | 9 +- examples/AutoBenchmark/README.md | 187 ++++++++++++++------------- examples/AutoBenchmark/esp32.txt | 153 +++++++++++----------- examples/AutoBenchmark/esp8266.txt | 133 ++++++++++--------- examples/AutoBenchmark/micro.txt | 108 ++++++++-------- examples/AutoBenchmark/nano.txt | 108 ++++++++-------- examples/AutoBenchmark/samd.txt | 157 +++++++++++----------- examples/AutoBenchmark/stm32.txt | 155 +++++++++++----------- examples/AutoBenchmark/teensy32.txt | 145 +++++++++++---------- 9 files changed, 601 insertions(+), 554 deletions(-) diff --git a/examples/AutoBenchmark/Benchmark.cpp b/examples/AutoBenchmark/Benchmark.cpp index f9579d3..2cee64f 100644 --- a/examples/AutoBenchmark/Benchmark.cpp +++ b/examples/AutoBenchmark/Benchmark.cpp @@ -18,6 +18,7 @@ using ace_common::GenericStats; using ace_common::isSorted; using ace_sorting::bubbleSort; using ace_sorting::insertionSort; +using ace_sorting::selectionSort; using ace_sorting::shellSortClassic; using ace_sorting::shellSortKnuth; using ace_sorting::shellSortTokuda; @@ -150,8 +151,12 @@ static void runSortForSizes( SortFunction sortFunction) { for (uint16_t i = 0; i < NUM_DATA_SIZES; i++) { uint16_t dataSize = DATA_SIZES[i]; + + // Don't run O(N^2) sorting algorithms on large arrays because they take too + // long to finish. if (sortFunction == &bubbleSort - || sortFunction == &insertionSort) { + || sortFunction == &insertionSort + || sortFunction == &selectionSort) { if (dataSize > 1000) break; } @@ -180,6 +185,8 @@ void runBenchmarks() { #endif runSortForSizes( F("insertionSort()"), SLOW_SAMPLE_SIZE, insertionSort); + runSortForSizes( + F("selectionSort()"), SLOW_SAMPLE_SIZE, selectionSort); runSortForSizes( F("shellSortClassic()"), FAST_SAMPLE_SIZE, shellSortClassic); diff --git a/examples/AutoBenchmark/README.md b/examples/AutoBenchmark/README.md index 23c9375..5d404e1 100644 --- a/examples/AutoBenchmark/README.md +++ b/examples/AutoBenchmark/README.md @@ -71,23 +71,24 @@ when sorting different array sizes. | \ N | 10 | 30 | 100 | 300 | 1000 | 3000 | | Function \ | | | | | | | |---------------------+-------+-------+--------+---------+---------+---------| -| bubbleSort() | 0.101 | 0.989 | 11.841 | 112.304 | | | -| insertionSort() | 0.045 | 0.275 | 2.601 | 21.651 | | | +| bubbleSort() | 0.107 | 1.077 | 12.735 | 116.675 | | | +| insertionSort() | 0.045 | 0.263 | 2.557 | 22.252 | | | +| selectionSort() | 0.088 | 0.560 | 5.600 | 48.892 | | | |---------------------+-------+-------+--------+---------+---------+---------| -| shellSortClassic() | 0.090 | 0.365 | 1.797 | 7.412 | | | -| shellSortKnuth() | 0.102 | 0.329 | 1.443 | 5.728 | | | -| shellSortTokuda() | 0.074 | 0.340 | 1.631 | 6.554 | | | +| shellSortClassic() | 0.074 | 0.310 | 1.706 | 6.865 | | | +| shellSortKnuth() | 0.101 | 0.330 | 1.450 | 5.665 | | | +| shellSortTokuda() | 0.075 | 0.327 | 1.614 | 6.540 | | | |---------------------+-------+-------+--------+---------+---------+---------| -| combSort13() | 0.163 | 0.550 | 2.220 | 8.135 | | | -| combSort13m() | 0.164 | 0.551 | 2.238 | 8.141 | | | -| combSort133() | 0.085 | 0.388 | 1.950 | 7.691 | | | -| combSort133m() | 0.089 | 0.419 | 1.995 | 7.730 | | | +| combSort13() | 0.160 | 0.534 | 2.214 | 8.167 | | | +| combSort13m() | 0.165 | 0.550 | 2.219 | 8.181 | | | +| combSort133() | 0.086 | 0.396 | 1.944 | 7.702 | | | +| combSort133m() | 0.086 | 0.416 | 1.978 | 7.740 | | | |---------------------+-------+-------+--------+---------+---------+---------| -| quickSortMiddle() | 0.096 | 0.374 | 1.558 | 5.665 | | | -| quickSortMedian() | 0.118 | 0.429 | 1.711 | 5.863 | | | -| quickSortMdnSwppd() | 0.091 | 0.334 | 1.399 | 4.893 | | | +| quickSortMiddle() | 0.096 | 0.368 | 1.568 | 5.651 | | | +| quickSortMedian() | 0.117 | 0.431 | 1.717 | 5.905 | | | +| quickSortMdnSwppd() | 0.094 | 0.341 | 1.417 | 4.909 | | | |---------------------+-------+-------+--------+---------+---------+---------| -| qsort() | 0.203 | 0.863 | 3.663 | 13.016 | | | +| qsort() | 0.204 | 0.855 | 3.629 | 13.021 | | | +---------------------+-------+-------+--------+---------+---------+---------+ ``` @@ -104,23 +105,24 @@ when sorting different array sizes. | \ N | 10 | 30 | 100 | 300 | 1000 | 3000 | | Function \ | | | | | | | |---------------------+-------+-------+--------+---------+---------+---------| -| bubbleSort() | 0.112 | 1.011 | 13.172 | 118.507 | | | -| insertionSort() | 0.048 | 0.269 | 2.481 | 22.068 | | | +| bubbleSort() | 0.115 | 1.083 | 12.773 | 121.179 | | | +| insertionSort() | 0.041 | 0.291 | 2.527 | 21.032 | | | +| selectionSort() | 0.081 | 0.561 | 5.632 | 49.153 | | | |---------------------+-------+-------+--------+---------+---------+---------| -| shellSortClassic() | 0.090 | 0.370 | 1.825 | 7.457 | | | -| shellSortKnuth() | 0.100 | 0.333 | 1.437 | 5.730 | | | -| shellSortTokuda() | 0.076 | 0.338 | 1.627 | 6.553 | | | +| shellSortClassic() | 0.074 | 0.310 | 1.712 | 6.912 | | | +| shellSortKnuth() | 0.101 | 0.339 | 1.445 | 5.601 | | | +| shellSortTokuda() | 0.076 | 0.337 | 1.634 | 6.588 | | | |---------------------+-------+-------+--------+---------+---------+---------| -| combSort13() | 0.165 | 0.544 | 2.291 | 8.196 | | | -| combSort13m() | 0.163 | 0.556 | 2.236 | 8.131 | | | -| combSort133() | 0.087 | 0.396 | 1.982 | 7.762 | | | -| combSort133m() | 0.088 | 0.422 | 1.985 | 7.759 | | | +| combSort13() | 0.165 | 0.537 | 2.209 | 8.215 | | | +| combSort13m() | 0.164 | 0.557 | 2.219 | 8.134 | | | +| combSort133() | 0.086 | 0.389 | 1.996 | 7.767 | | | +| combSort133m() | 0.091 | 0.423 | 1.997 | 7.729 | | | |---------------------+-------+-------+--------+---------+---------+---------| -| quickSortMiddle() | 0.096 | 0.367 | 1.566 | 5.604 | | | -| quickSortMedian() | 0.120 | 0.424 | 1.722 | 5.928 | | | -| quickSortMdnSwppd() | 0.089 | 0.340 | 1.394 | 4.957 | | | +| quickSortMiddle() | 0.099 | 0.375 | 1.619 | 5.711 | | | +| quickSortMedian() | 0.119 | 0.427 | 1.748 | 5.976 | | | +| quickSortMdnSwppd() | 0.094 | 0.341 | 1.401 | 4.974 | | | |---------------------+-------+-------+--------+---------+---------+---------| -| qsort() | 0.206 | 0.834 | 3.649 | 13.080 | | | +| qsort() | 0.200 | 0.839 | 3.661 | 12.974 | | | +---------------------+-------+-------+--------+---------+---------+---------+ ``` @@ -136,23 +138,24 @@ when sorting different array sizes. | \ N | 10 | 30 | 100 | 300 | 1000 | 3000 | | Function \ | | | | | | | |---------------------+-------+-------+--------+---------+---------+---------| -| bubbleSort() | 0.033 | 0.341 | 3.915 | 36.720 | 413.076 | | -| insertionSort() | 0.018 | 0.094 | 0.936 | 8.204 | 87.954 | | +| bubbleSort() | 0.039 | 0.357 | 3.984 | 36.967 | 429.557 | | +| insertionSort() | 0.014 | 0.095 | 0.880 | 8.132 | 87.197 | | +| selectionSort() | 0.023 | 0.159 | 1.620 | 14.279 | 157.547 | | |---------------------+-------+-------+--------+---------+---------+---------| -| shellSortClassic() | 0.022 | 0.085 | 0.416 | 1.700 | 7.543 | 27.936 | -| shellSortKnuth() | 0.019 | 0.066 | 0.293 | 1.150 | 5.078 | 19.490 | -| shellSortTokuda() | 0.020 | 0.082 | 0.392 | 1.558 | 6.689 | 24.188 | +| shellSortClassic() | 0.016 | 0.064 | 0.349 | 1.405 | 5.861 | 22.452 | +| shellSortKnuth() | 0.019 | 0.067 | 0.289 | 1.153 | 5.111 | 19.448 | +| shellSortTokuda() | 0.020 | 0.081 | 0.390 | 1.556 | 6.673 | 24.187 | |---------------------+-------+-------+--------+---------+---------+---------| -| combSort13() | 0.035 | 0.120 | 0.510 | 1.848 | 8.194 | 29.611 | -| combSort13m() | 0.036 | 0.125 | 0.512 | 1.872 | 7.944 | 28.631 | -| combSort133() | 0.021 | 0.091 | 0.448 | 1.754 | 7.939 | 27.346 | -| combSort133m() | 0.022 | 0.099 | 0.456 | 1.752 | 7.621 | 26.992 | +| combSort13() | 0.035 | 0.118 | 0.496 | 1.859 | 8.180 | 29.661 | +| combSort13m() | 0.035 | 0.124 | 0.512 | 1.882 | 7.892 | 28.483 | +| combSort133() | 0.020 | 0.090 | 0.454 | 1.764 | 7.897 | 26.989 | +| combSort133m() | 0.021 | 0.097 | 0.454 | 1.752 | 7.623 | 27.649 | |---------------------+-------+-------+--------+---------+---------+---------| -| quickSortMiddle() | 0.021 | 0.075 | 0.311 | 1.065 | 4.237 | 14.362 | -| quickSortMedian() | 0.026 | 0.087 | 0.348 | 1.167 | 4.402 | 14.555 | -| quickSortMdnSwppd() | 0.020 | 0.071 | 0.282 | 0.982 | 3.775 | 12.711 | +| quickSortMiddle() | 0.021 | 0.073 | 0.315 | 1.077 | 4.211 | 14.031 | +| quickSortMedian() | 0.026 | 0.088 | 0.344 | 1.161 | 4.343 | 14.455 | +| quickSortMdnSwppd() | 0.020 | 0.070 | 0.285 | 1.001 | 3.783 | 12.630 | |---------------------+-------+-------+--------+---------+---------+---------| -| qsort() | 0.050 | 0.206 | 0.861 | 3.071 | 11.883 | 40.299 | +| qsort() | 0.054 | 0.213 | 0.886 | 3.215 | 12.678 | 42.791 | +---------------------+-------+-------+--------+---------+---------+---------+ ``` @@ -168,23 +171,24 @@ when sorting different array sizes. | \ N | 10 | 30 | 100 | 300 | 1000 | 3000 | | Function \ | | | | | | | |---------------------+-------+-------+--------+---------+---------+---------| -| bubbleSort() | 0.019 | 0.200 | 2.056 | 19.174 | 229.211 | | -| insertionSort() | 0.009 | 0.053 | 0.512 | 4.584 | 49.112 | | +| bubbleSort() | 0.018 | 0.161 | 2.105 | 19.955 | 225.639 | | +| insertionSort() | 0.010 | 0.054 | 0.495 | 4.486 | 48.616 | | +| selectionSort() | 0.017 | 0.116 | 1.167 | 10.197 | 112.180 | | |---------------------+-------+-------+--------+---------+---------+---------| -| shellSortClassic() | 0.018 | 0.074 | 0.363 | 1.492 | 6.411 | 23.660 | -| shellSortKnuth() | 0.014 | 0.059 | 0.290 | 1.182 | 5.308 | 20.425 | -| shellSortTokuda() | 0.011 | 0.048 | 0.228 | 0.915 | 3.888 | 14.116 | +| shellSortClassic() | 0.014 | 0.058 | 0.324 | 1.284 | 5.427 | 20.852 | +| shellSortKnuth() | 0.014 | 0.059 | 0.305 | 1.236 | 5.604 | 21.566 | +| shellSortTokuda() | 0.011 | 0.047 | 0.226 | 0.901 | 3.904 | 14.199 | |---------------------+-------+-------+--------+---------+---------+---------| -| combSort13() | 0.019 | 0.090 | 0.452 | 1.794 | 8.182 | 30.001 | -| combSort13m() | 0.020 | 0.091 | 0.446 | 1.715 | 7.666 | 27.604 | -| combSort133() | 0.018 | 0.084 | 0.429 | 1.685 | 7.692 | 26.113 | -| combSort133m() | 0.018 | 0.092 | 0.434 | 1.702 | 7.481 | 26.431 | +| combSort13() | 0.019 | 0.087 | 0.442 | 1.770 | 7.895 | 28.862 | +| combSort13m() | 0.018 | 0.087 | 0.430 | 1.697 | 7.380 | 26.657 | +| combSort133() | 0.018 | 0.085 | 0.417 | 1.649 | 7.630 | 26.148 | +| combSort133m() | 0.019 | 0.089 | 0.419 | 1.619 | 7.151 | 25.380 | |---------------------+-------+-------+--------+---------+---------+---------| -| quickSortMiddle() | 0.018 | 0.069 | 0.292 | 1.041 | 4.061 | 13.649 | -| quickSortMedian() | 0.021 | 0.078 | 0.314 | 1.120 | 4.218 | 14.402 | -| quickSortMdnSwppd() | 0.014 | 0.054 | 0.232 | 0.831 | 3.249 | 11.240 | +| quickSortMiddle() | 0.019 | 0.067 | 0.278 | 0.990 | 3.835 | 13.145 | +| quickSortMedian() | 0.020 | 0.076 | 0.311 | 1.101 | 4.212 | 14.381 | +| quickSortMdnSwppd() | 0.015 | 0.056 | 0.228 | 0.836 | 3.285 | 11.265 | |---------------------+-------+-------+--------+---------+---------+---------| -| qsort() | 0.032 | 0.134 | 0.573 | 2.124 | 8.337 | 28.772 | +| qsort() | 0.034 | 0.149 | 0.615 | 2.221 | 8.921 | 30.627 | +---------------------+-------+-------+--------+---------+---------+---------+ ``` @@ -200,23 +204,24 @@ when sorting different array sizes. | \ N | 10 | 30 | 100 | 300 | 1000 | 3000 | | Function \ | | | | | | | |---------------------+-------+-------+--------+---------+---------+---------| -| bubbleSort() | 0.021 | 0.191 | 2.232 | 20.144 | 225.651 | | +| bubbleSort() | 0.021 | 0.192 | 2.231 | 20.143 | 225.651 | | | insertionSort() | 0.009 | 0.037 | 0.362 | 3.220 | 34.646 | | +| selectionSort() | 0.017 | 0.085 | 0.892 | 7.930 | 87.723 | | |---------------------+-------+-------+--------+---------+---------+---------| -| shellSortClassic() | 0.013 | 0.050 | 0.246 | 1.020 | 4.402 | 16.259 | -| shellSortKnuth() | 0.010 | 0.036 | 0.173 | 0.691 | 3.016 | 11.270 | -| shellSortTokuda() | 0.009 | 0.038 | 0.181 | 0.730 | 3.141 | 11.368 | +| shellSortClassic() | 0.011 | 0.039 | 0.215 | 0.878 | 3.609 | 13.789 | +| shellSortKnuth() | 0.010 | 0.036 | 0.172 | 0.690 | 3.022 | 11.304 | +| shellSortTokuda() | 0.009 | 0.039 | 0.183 | 0.735 | 3.140 | 11.366 | |---------------------+-------+-------+--------+---------+---------+---------| -| combSort13() | 0.013 | 0.049 | 0.229 | 0.836 | 3.810 | 13.769 | -| combSort13m() | 0.013 | 0.051 | 0.225 | 0.842 | 3.621 | 13.130 | -| combSort133() | 0.010 | 0.040 | 0.210 | 0.804 | 3.603 | 12.406 | -| combSort133m() | 0.010 | 0.044 | 0.205 | 0.803 | 3.448 | 12.407 | +| combSort13() | 0.013 | 0.048 | 0.219 | 0.846 | 3.711 | 13.689 | +| combSort13m() | 0.014 | 0.051 | 0.222 | 0.840 | 3.622 | 13.104 | +| combSort133() | 0.010 | 0.040 | 0.208 | 0.796 | 3.571 | 12.430 | +| combSort133m() | 0.010 | 0.044 | 0.206 | 0.793 | 3.465 | 12.387 | |---------------------+-------+-------+--------+---------+---------+---------| -| quickSortMiddle() | 0.013 | 0.046 | 0.186 | 0.641 | 2.470 | 8.390 | -| quickSortMedian() | 0.016 | 0.052 | 0.201 | 0.679 | 2.577 | 8.439 | -| quickSortMdnSwppd() | 0.012 | 0.039 | 0.158 | 0.550 | 2.116 | 7.180 | +| quickSortMiddle() | 0.013 | 0.045 | 0.185 | 0.651 | 2.519 | 8.307 | +| quickSortMedian() | 0.016 | 0.052 | 0.200 | 0.677 | 2.551 | 8.403 | +| quickSortMdnSwppd() | 0.012 | 0.039 | 0.159 | 0.558 | 2.122 | 7.109 | |---------------------+-------+-------+--------+---------+---------+---------| -| qsort() | 0.027 | 0.092 | 0.414 | 1.501 | 6.002 | 20.681 | +| qsort() | 0.028 | 0.092 | 0.416 | 1.516 | 6.010 | 20.789 | +---------------------+-------+-------+--------+---------+---------+---------+ ``` @@ -232,23 +237,24 @@ when sorting different array sizes. | \ N | 10 | 30 | 100 | 300 | 1000 | 3000 | | Function \ | | | | | | | |---------------------+-------+-------+--------+---------+---------+---------| -| bubbleSort() | 0.006 | 0.052 | 0.624 | 5.731 | 63.186 | | -| insertionSort() | 0.004 | 0.016 | 0.159 | 1.403 | 14.734 | | +| bubbleSort() | 0.006 | 0.049 | 0.622 | 5.704 | 63.678 | | +| insertionSort() | 0.004 | 0.017 | 0.157 | 1.295 | 15.081 | | +| selectionSort() | 0.005 | 0.032 | 0.341 | 3.035 | 33.618 | | |---------------------+-------+-------+--------+---------+---------+---------| -| shellSortClassic() | 0.005 | 0.017 | 0.079 | 0.326 | 1.441 | 5.334 | -| shellSortKnuth() | 0.004 | 0.013 | 0.061 | 0.250 | 1.097 | 4.168 | -| shellSortTokuda() | 0.004 | 0.014 | 0.065 | 0.256 | 1.111 | 4.031 | +| shellSortClassic() | 0.004 | 0.014 | 0.077 | 0.302 | 1.283 | 4.861 | +| shellSortKnuth() | 0.004 | 0.013 | 0.062 | 0.247 | 1.110 | 4.155 | +| shellSortTokuda() | 0.004 | 0.014 | 0.065 | 0.263 | 1.115 | 4.034 | |---------------------+-------+-------+--------+---------+---------+---------| -| combSort13() | 0.004 | 0.019 | 0.094 | 0.376 | 1.677 | 6.256 | -| combSort13m() | 0.005 | 0.021 | 0.098 | 0.381 | 1.651 | 5.984 | -| combSort133() | 0.004 | 0.019 | 0.091 | 0.368 | 1.678 | 5.718 | -| combSort133m() | 0.005 | 0.020 | 0.095 | 0.365 | 1.584 | 5.682 | +| combSort13() | 0.005 | 0.019 | 0.095 | 0.377 | 1.688 | 6.257 | +| combSort13m() | 0.005 | 0.020 | 0.097 | 0.373 | 1.641 | 5.996 | +| combSort133() | 0.005 | 0.019 | 0.091 | 0.365 | 1.644 | 5.650 | +| combSort133m() | 0.005 | 0.021 | 0.096 | 0.368 | 1.599 | 5.661 | |---------------------+-------+-------+--------+---------+---------+---------| -| quickSortMiddle() | 0.005 | 0.018 | 0.071 | 0.259 | 1.005 | 3.401 | -| quickSortMedian() | 0.006 | 0.018 | 0.072 | 0.251 | 0.969 | 3.257 | -| quickSortMdnSwppd() | 0.004 | 0.014 | 0.059 | 0.205 | 0.817 | 2.796 | +| quickSortMiddle() | 0.005 | 0.018 | 0.070 | 0.249 | 0.975 | 3.346 | +| quickSortMedian() | 0.006 | 0.018 | 0.072 | 0.255 | 0.967 | 3.249 | +| quickSortMdnSwppd() | 0.004 | 0.014 | 0.059 | 0.211 | 0.826 | 2.803 | |---------------------+-------+-------+--------+---------+---------+---------| -| qsort() | 0.008 | 0.032 | 0.144 | 0.525 | 2.109 | 7.245 | +| qsort() | 0.008 | 0.032 | 0.143 | 0.524 | 2.099 | 7.221 | +---------------------+-------+-------+--------+---------+---------+---------+ ``` @@ -265,23 +271,24 @@ when sorting different array sizes. | \ N | 10 | 30 | 100 | 300 | 1000 | 3000 | | Function \ | | | | | | | |---------------------+-------+-------+--------+---------+---------+---------| -| bubbleSort() | 0.008 | 0.077 | 0.957 | 8.534 | 97.649 | | -| insertionSort() | 0.006 | 0.044 | 0.392 | 3.410 | 36.368 | | +| bubbleSort() | 0.009 | 0.079 | 0.824 | 8.469 | 98.471 | | +| insertionSort() | 0.006 | 0.041 | 0.394 | 3.390 | 36.820 | | +| selectionSort() | 0.008 | 0.057 | 0.590 | 5.215 | 57.558 | | |---------------------+-------+-------+--------+---------+---------+---------| -| shellSortClassic() | 0.009 | 0.034 | 0.168 | 0.688 | 3.021 | 11.131 | -| shellSortKnuth() | 0.006 | 0.027 | 0.131 | 0.524 | 2.326 | 8.970 | -| shellSortTokuda() | 0.007 | 0.028 | 0.137 | 0.542 | 2.311 | 8.349 | +| shellSortClassic() | 0.007 | 0.029 | 0.162 | 0.648 | 2.712 | 10.394 | +| shellSortKnuth() | 0.006 | 0.027 | 0.133 | 0.531 | 2.339 | 8.903 | +| shellSortTokuda() | 0.007 | 0.028 | 0.136 | 0.539 | 2.314 | 8.366 | |---------------------+-------+-------+--------+---------+---------+---------| -| combSort13() | 0.008 | 0.036 | 0.179 | 0.716 | 3.253 | 11.911 | -| combSort13m() | 0.009 | 0.038 | 0.185 | 0.719 | 3.139 | 11.372 | -| combSort133() | 0.008 | 0.035 | 0.170 | 0.695 | 3.169 | 10.965 | -| combSort133m() | 0.008 | 0.038 | 0.180 | 0.702 | 3.016 | 10.884 | +| combSort13() | 0.008 | 0.036 | 0.182 | 0.722 | 3.233 | 11.887 | +| combSort13m() | 0.008 | 0.038 | 0.186 | 0.725 | 3.139 | 11.431 | +| combSort133() | 0.008 | 0.035 | 0.174 | 0.698 | 3.101 | 10.902 | +| combSort133m() | 0.008 | 0.038 | 0.180 | 0.710 | 3.030 | 10.801 | |---------------------+-------+-------+--------+---------+---------+---------| -| quickSortMiddle() | 0.007 | 0.026 | 0.110 | 0.392 | 1.541 | 5.275 | -| quickSortMedian() | 0.009 | 0.030 | 0.122 | 0.414 | 1.605 | 5.358 | -| quickSortMdnSwppd() | 0.007 | 0.025 | 0.102 | 0.364 | 1.402 | 4.717 | +| quickSortMiddle() | 0.007 | 0.026 | 0.109 | 0.388 | 1.520 | 5.278 | +| quickSortMedian() | 0.009 | 0.030 | 0.122 | 0.423 | 1.590 | 5.387 | +| quickSortMdnSwppd() | 0.007 | 0.025 | 0.100 | 0.365 | 1.412 | 4.752 | |---------------------+-------+-------+--------+---------+---------+---------| -| qsort() | 0.017 | 0.072 | 0.313 | 1.154 | 4.585 | 15.785 | +| qsort() | 0.017 | 0.073 | 0.315 | 1.156 | 4.576 | 15.732 | +---------------------+-------+-------+--------+---------+---------+---------+ ``` diff --git a/examples/AutoBenchmark/esp32.txt b/examples/AutoBenchmark/esp32.txt index 8df1eb3..07495aa 100644 --- a/examples/AutoBenchmark/esp32.txt +++ b/examples/AutoBenchmark/esp32.txt @@ -1,78 +1,83 @@ BENCHMARKS -bubbleSort() 10 0.006 0.006 0.006 3 -bubbleSort() 30 0.044 0.052 0.058 3 -bubbleSort() 100 0.592 0.624 0.673 3 -bubbleSort() 300 5.413 5.731 5.940 3 -bubbleSort() 1000 61.303 63.186 64.731 3 -insertionSort() 10 0.003 0.004 0.007 3 -insertionSort() 30 0.015 0.016 0.018 3 -insertionSort() 100 0.151 0.159 0.170 3 -insertionSort() 300 1.388 1.403 1.412 3 -insertionSort() 1000 14.568 14.734 14.958 3 -shellSortClassic() 10 0.004 0.005 0.012 20 -shellSortClassic() 30 0.015 0.017 0.018 20 -shellSortClassic() 100 0.077 0.079 0.081 20 -shellSortClassic() 300 0.312 0.326 0.339 20 -shellSortClassic() 1000 1.391 1.441 1.485 20 -shellSortClassic() 3000 5.179 5.334 5.429 20 +bubbleSort() 10 0.004 0.006 0.008 3 +bubbleSort() 30 0.039 0.049 0.057 3 +bubbleSort() 100 0.592 0.622 0.640 3 +bubbleSort() 300 5.452 5.704 5.860 3 +bubbleSort() 1000 62.985 63.678 64.192 3 +insertionSort() 10 0.002 0.004 0.006 3 +insertionSort() 30 0.015 0.017 0.018 3 +insertionSort() 100 0.143 0.157 0.173 3 +insertionSort() 300 1.263 1.295 1.343 3 +insertionSort() 1000 14.992 15.081 15.257 3 +selectionSort() 10 0.004 0.005 0.007 3 +selectionSort() 30 0.032 0.032 0.033 3 +selectionSort() 100 0.338 0.341 0.346 3 +selectionSort() 300 3.035 3.035 3.035 3 +selectionSort() 1000 33.613 33.618 33.620 3 +shellSortClassic() 10 0.003 0.004 0.006 20 +shellSortClassic() 30 0.013 0.014 0.016 20 +shellSortClassic() 100 0.071 0.077 0.087 20 +shellSortClassic() 300 0.294 0.302 0.318 20 +shellSortClassic() 1000 1.250 1.283 1.347 20 +shellSortClassic() 3000 4.675 4.861 5.049 20 shellSortKnuth() 10 0.003 0.004 0.008 20 -shellSortKnuth() 30 0.011 0.013 0.017 20 -shellSortKnuth() 100 0.057 0.061 0.068 20 -shellSortKnuth() 300 0.238 0.250 0.263 20 -shellSortKnuth() 1000 1.054 1.097 1.154 20 -shellSortKnuth() 3000 4.005 4.168 4.381 20 -shellSortTokuda() 10 0.003 0.004 0.007 20 -shellSortTokuda() 30 0.013 0.014 0.021 20 -shellSortTokuda() 100 0.061 0.065 0.071 20 -shellSortTokuda() 300 0.250 0.256 0.262 20 -shellSortTokuda() 1000 1.095 1.111 1.133 20 -shellSortTokuda() 3000 3.995 4.031 4.075 20 -combSort13() 10 0.004 0.004 0.007 20 -combSort13() 30 0.017 0.019 0.023 20 -combSort13() 100 0.092 0.094 0.114 20 -combSort13() 300 0.357 0.376 0.411 20 -combSort13() 1000 1.638 1.677 1.797 20 -combSort13() 3000 5.826 6.256 6.734 20 -combSort13m() 10 0.004 0.005 0.008 20 -combSort13m() 30 0.020 0.021 0.028 20 -combSort13m() 100 0.092 0.098 0.122 20 -combSort13m() 300 0.358 0.381 0.411 20 -combSort13m() 1000 1.572 1.651 1.722 20 -combSort13m() 3000 5.819 5.984 6.284 20 -combSort133() 10 0.004 0.004 0.007 20 -combSort133() 30 0.018 0.019 0.026 20 +shellSortKnuth() 30 0.011 0.013 0.015 20 +shellSortKnuth() 100 0.058 0.062 0.070 20 +shellSortKnuth() 300 0.236 0.247 0.259 20 +shellSortKnuth() 1000 1.067 1.110 1.203 20 +shellSortKnuth() 3000 3.935 4.155 4.279 20 +shellSortTokuda() 10 0.003 0.004 0.008 20 +shellSortTokuda() 30 0.013 0.014 0.023 20 +shellSortTokuda() 100 0.062 0.065 0.075 20 +shellSortTokuda() 300 0.255 0.263 0.274 20 +shellSortTokuda() 1000 1.100 1.115 1.144 20 +shellSortTokuda() 3000 4.003 4.034 4.061 20 +combSort13() 10 0.004 0.005 0.008 20 +combSort13() 30 0.018 0.019 0.021 20 +combSort13() 100 0.092 0.095 0.100 20 +combSort13() 300 0.358 0.377 0.410 20 +combSort13() 1000 1.571 1.688 1.789 20 +combSort13() 3000 5.826 6.257 6.734 20 +combSort13m() 10 0.003 0.005 0.008 20 +combSort13m() 30 0.020 0.020 0.022 20 +combSort13m() 100 0.092 0.097 0.107 20 +combSort13m() 300 0.358 0.373 0.389 20 +combSort13m() 1000 1.565 1.641 1.714 20 +combSort13m() 3000 5.827 5.996 6.053 20 +combSort133() 10 0.004 0.005 0.008 20 +combSort133() 30 0.018 0.019 0.021 20 combSort133() 100 0.085 0.091 0.108 20 -combSort133() 300 0.342 0.368 0.394 20 -combSort133() 1000 1.519 1.678 1.969 20 -combSort133() 3000 5.442 5.718 5.900 20 -combSort133m() 10 0.004 0.005 0.008 20 -combSort133m() 30 0.020 0.020 0.021 20 -combSort133m() 100 0.092 0.095 0.108 20 -combSort133m() 300 0.342 0.365 0.387 20 -combSort133m() 1000 1.513 1.584 1.595 20 -combSort133m() 3000 5.443 5.682 6.125 20 -quickSortMiddle() 10 0.004 0.005 0.013 20 -quickSortMiddle() 30 0.015 0.018 0.027 20 -quickSortMiddle() 100 0.062 0.071 0.083 20 -quickSortMiddle() 300 0.230 0.259 0.302 20 -quickSortMiddle() 1000 0.889 1.005 1.139 20 -quickSortMiddle() 3000 3.118 3.401 3.869 20 -quickSortMedian() 10 0.004 0.006 0.011 20 -quickSortMedian() 30 0.016 0.018 0.025 20 -quickSortMedian() 100 0.068 0.072 0.082 20 -quickSortMedian() 300 0.241 0.251 0.270 20 -quickSortMedian() 1000 0.916 0.969 1.018 20 -quickSortMedian() 3000 3.097 3.257 3.458 20 -quickSortMedianSwapped() 10 0.003 0.004 0.010 20 -quickSortMedianSwapped() 30 0.012 0.014 0.015 20 -quickSortMedianSwapped() 100 0.054 0.059 0.063 20 -quickSortMedianSwapped() 300 0.193 0.205 0.224 20 -quickSortMedianSwapped() 1000 0.779 0.817 0.866 20 -quickSortMedianSwapped() 3000 2.702 2.796 2.953 20 -qsort() 10 0.006 0.008 0.013 20 -qsort() 30 0.029 0.032 0.036 20 -qsort() 100 0.133 0.144 0.179 20 -qsort() 300 0.503 0.525 0.566 20 -qsort() 1000 2.055 2.109 2.169 20 -qsort() 3000 7.148 7.245 7.388 20 +combSort133() 300 0.341 0.365 0.409 20 +combSort133() 1000 1.519 1.644 1.812 20 +combSort133() 3000 5.442 5.650 6.125 20 +combSort133m() 10 0.004 0.005 0.007 20 +combSort133m() 30 0.020 0.021 0.028 20 +combSort133m() 100 0.092 0.096 0.108 20 +combSort133m() 300 0.341 0.368 0.394 20 +combSort133m() 1000 1.587 1.599 1.670 20 +combSort133m() 3000 5.442 5.661 6.350 20 +quickSortMiddle() 10 0.004 0.005 0.008 20 +quickSortMiddle() 30 0.014 0.018 0.027 20 +quickSortMiddle() 100 0.062 0.070 0.083 20 +quickSortMiddle() 300 0.218 0.249 0.296 20 +quickSortMiddle() 1000 0.886 0.975 1.064 20 +quickSortMiddle() 3000 3.149 3.346 3.712 20 +quickSortMedian() 10 0.005 0.006 0.010 20 +quickSortMedian() 30 0.016 0.018 0.020 20 +quickSortMedian() 100 0.068 0.072 0.083 20 +quickSortMedian() 300 0.235 0.255 0.271 20 +quickSortMedian() 1000 0.920 0.967 1.054 20 +quickSortMedian() 3000 3.106 3.249 3.393 20 +quickSortMedianSwapped() 10 0.003 0.004 0.011 20 +quickSortMedianSwapped() 30 0.013 0.014 0.016 20 +quickSortMedianSwapped() 100 0.056 0.059 0.068 20 +quickSortMedianSwapped() 300 0.200 0.211 0.224 20 +quickSortMedianSwapped() 1000 0.794 0.826 0.898 20 +quickSortMedianSwapped() 3000 2.694 2.803 2.989 20 +qsort() 10 0.006 0.008 0.017 20 +qsort() 30 0.029 0.032 0.042 20 +qsort() 100 0.132 0.143 0.160 20 +qsort() 300 0.509 0.524 0.551 20 +qsort() 1000 2.043 2.099 2.169 20 +qsort() 3000 7.136 7.221 7.391 20 END diff --git a/examples/AutoBenchmark/esp8266.txt b/examples/AutoBenchmark/esp8266.txt index 721dba7..3e28d90 100644 --- a/examples/AutoBenchmark/esp8266.txt +++ b/examples/AutoBenchmark/esp8266.txt @@ -1,78 +1,83 @@ BENCHMARKS bubbleSort() 10 0.014 0.021 0.031 3 -bubbleSort() 30 0.184 0.191 0.198 3 -bubbleSort() 100 2.177 2.232 2.318 3 -bubbleSort() 300 18.916 20.144 21.186 3 +bubbleSort() 30 0.184 0.192 0.199 3 +bubbleSort() 100 2.177 2.231 2.318 3 +bubbleSort() 300 18.915 20.143 21.185 3 bubbleSort() 1000 222.008 225.651 230.578 3 insertionSort() 10 0.006 0.009 0.013 3 insertionSort() 30 0.036 0.037 0.039 3 insertionSort() 100 0.338 0.362 0.383 3 insertionSort() 300 3.106 3.220 3.331 3 -insertionSort() 1000 34.432 34.646 35.044 3 -shellSortClassic() 10 0.011 0.013 0.027 20 -shellSortClassic() 30 0.047 0.050 0.052 20 -shellSortClassic() 100 0.239 0.246 0.258 20 -shellSortClassic() 300 0.996 1.020 1.052 20 -shellSortClassic() 1000 4.306 4.402 4.512 20 -shellSortClassic() 3000 15.748 16.259 16.880 20 +insertionSort() 1000 34.432 34.646 35.043 3 +selectionSort() 10 0.011 0.017 0.028 3 +selectionSort() 30 0.084 0.085 0.085 3 +selectionSort() 100 0.891 0.892 0.892 3 +selectionSort() 300 7.924 7.930 7.939 3 +selectionSort() 1000 87.681 87.723 87.751 3 +shellSortClassic() 10 0.009 0.011 0.024 20 +shellSortClassic() 30 0.037 0.039 0.041 20 +shellSortClassic() 100 0.205 0.215 0.226 20 +shellSortClassic() 300 0.848 0.878 0.907 20 +shellSortClassic() 1000 3.506 3.609 3.755 20 +shellSortClassic() 3000 13.416 13.789 14.644 20 shellSortKnuth() 10 0.008 0.010 0.029 20 shellSortKnuth() 30 0.033 0.036 0.041 20 -shellSortKnuth() 100 0.165 0.173 0.180 20 -shellSortKnuth() 300 0.666 0.691 0.738 20 -shellSortKnuth() 1000 2.926 3.016 3.149 20 -shellSortKnuth() 3000 10.992 11.270 11.644 20 -shellSortTokuda() 10 0.007 0.009 0.020 20 -shellSortTokuda() 30 0.036 0.038 0.039 20 -shellSortTokuda() 100 0.175 0.181 0.188 20 -shellSortTokuda() 300 0.716 0.730 0.751 20 -shellSortTokuda() 1000 3.103 3.141 3.182 20 -shellSortTokuda() 3000 11.285 11.368 11.458 20 +shellSortKnuth() 100 0.159 0.172 0.186 20 +shellSortKnuth() 300 0.664 0.690 0.722 20 +shellSortKnuth() 1000 2.882 3.022 3.250 20 +shellSortKnuth() 3000 10.877 11.304 12.011 20 +shellSortTokuda() 10 0.008 0.009 0.020 20 +shellSortTokuda() 30 0.036 0.039 0.042 20 +shellSortTokuda() 100 0.177 0.183 0.188 20 +shellSortTokuda() 300 0.724 0.735 0.745 20 +shellSortTokuda() 1000 3.088 3.140 3.211 20 +shellSortTokuda() 3000 11.265 11.366 11.473 20 combSort13() 10 0.012 0.013 0.024 20 -combSort13() 30 0.045 0.049 0.051 20 -combSort13() 100 0.213 0.229 0.264 20 -combSort13() 300 0.803 0.836 0.902 20 -combSort13() 1000 3.611 3.810 4.103 20 -combSort13() 3000 12.775 13.769 15.203 20 -combSort13m() 10 0.012 0.013 0.028 20 -combSort13m() 30 0.050 0.051 0.051 20 -combSort13m() 100 0.213 0.225 0.247 20 -combSort13m() 300 0.804 0.842 0.902 20 -combSort13m() 1000 3.449 3.621 3.776 20 -combSort13m() 3000 12.759 13.130 13.752 20 -combSort133() 10 0.008 0.010 0.020 20 -combSort133() 30 0.039 0.040 0.044 20 -combSort133() 100 0.188 0.210 0.254 20 -combSort133() 300 0.751 0.804 0.853 20 -combSort133() 1000 3.315 3.603 3.966 20 -combSort133() 3000 11.911 12.406 13.392 20 +combSort13() 30 0.045 0.048 0.051 20 +combSort13() 100 0.196 0.219 0.247 20 +combSort13() 300 0.803 0.846 0.951 20 +combSort13() 1000 3.611 3.711 4.106 20 +combSort13() 3000 12.774 13.689 14.229 20 +combSort13m() 10 0.011 0.014 0.028 20 +combSort13m() 30 0.050 0.051 0.056 20 +combSort13m() 100 0.213 0.222 0.247 20 +combSort13m() 300 0.804 0.840 0.904 20 +combSort13m() 1000 3.611 3.622 3.775 20 +combSort13m() 3000 12.754 13.104 13.735 20 +combSort133() 10 0.008 0.010 0.017 20 +combSort133() 30 0.039 0.040 0.040 20 +combSort133() 100 0.188 0.208 0.270 20 +combSort133() 300 0.751 0.796 0.997 20 +combSort133() 1000 3.315 3.571 3.804 20 +combSort133() 3000 11.911 12.430 12.895 20 combSort133m() 10 0.009 0.010 0.017 20 combSort133m() 30 0.043 0.044 0.049 20 -combSort133m() 100 0.203 0.205 0.221 20 -combSort133m() 300 0.753 0.803 0.855 20 -combSort133m() 1000 3.315 3.448 3.496 20 -combSort133m() 3000 11.914 12.407 12.893 20 -quickSortMiddle() 10 0.010 0.013 0.028 20 -quickSortMiddle() 30 0.041 0.046 0.051 20 -quickSortMiddle() 100 0.173 0.186 0.263 20 -quickSortMiddle() 300 0.593 0.641 0.708 20 -quickSortMiddle() 1000 2.350 2.470 2.677 20 -quickSortMiddle() 3000 7.918 8.390 9.083 20 -quickSortMedian() 10 0.013 0.016 0.034 20 -quickSortMedian() 30 0.049 0.052 0.056 20 -quickSortMedian() 100 0.190 0.201 0.225 20 -quickSortMedian() 300 0.654 0.679 0.707 20 -quickSortMedian() 1000 2.507 2.577 2.698 20 -quickSortMedian() 3000 8.159 8.439 9.145 20 +combSort133m() 100 0.204 0.206 0.221 20 +combSort133m() 300 0.753 0.793 0.804 20 +combSort133m() 1000 3.317 3.465 3.497 20 +combSort133m() 3000 11.916 12.387 13.395 20 +quickSortMiddle() 10 0.011 0.013 0.027 20 +quickSortMiddle() 30 0.039 0.045 0.052 20 +quickSortMiddle() 100 0.162 0.185 0.213 20 +quickSortMiddle() 300 0.602 0.651 0.755 20 +quickSortMiddle() 1000 2.359 2.519 2.770 20 +quickSortMiddle() 3000 7.920 8.307 8.785 20 +quickSortMedian() 10 0.013 0.016 0.035 20 +quickSortMedian() 30 0.046 0.052 0.055 20 +quickSortMedian() 100 0.186 0.200 0.216 20 +quickSortMedian() 300 0.640 0.677 0.715 20 +quickSortMedian() 1000 2.461 2.551 2.642 20 +quickSortMedian() 3000 8.200 8.403 8.587 20 quickSortMedianSwapped() 10 0.009 0.012 0.035 20 -quickSortMedianSwapped() 30 0.036 0.039 0.045 20 -quickSortMedianSwapped() 100 0.148 0.158 0.167 20 -quickSortMedianSwapped() 300 0.526 0.550 0.588 20 -quickSortMedianSwapped() 1000 2.035 2.116 2.237 20 -quickSortMedianSwapped() 3000 6.886 7.180 7.633 20 -qsort() 10 0.018 0.027 0.137 20 -qsort() 30 0.084 0.092 0.101 20 -qsort() 100 0.397 0.414 0.439 20 -qsort() 300 1.465 1.501 1.580 20 -qsort() 1000 5.900 6.002 6.166 20 -qsort() 3000 20.412 20.681 20.989 20 +quickSortMedianSwapped() 30 0.034 0.039 0.045 20 +quickSortMedianSwapped() 100 0.150 0.159 0.186 20 +quickSortMedianSwapped() 300 0.530 0.558 0.597 20 +quickSortMedianSwapped() 1000 2.029 2.122 2.304 20 +quickSortMedianSwapped() 3000 6.933 7.109 7.609 20 +qsort() 10 0.017 0.028 0.150 20 +qsort() 30 0.085 0.092 0.105 20 +qsort() 100 0.399 0.416 0.450 20 +qsort() 300 1.480 1.516 1.694 20 +qsort() 1000 5.884 6.010 6.152 20 +qsort() 3000 20.491 20.789 21.354 20 END diff --git a/examples/AutoBenchmark/micro.txt b/examples/AutoBenchmark/micro.txt index f89f105..5b18b42 100644 --- a/examples/AutoBenchmark/micro.txt +++ b/examples/AutoBenchmark/micro.txt @@ -1,54 +1,58 @@ BENCHMARKS -bubbleSort() 10 0.096 0.112 0.128 3 -bubbleSort() 30 0.984 1.011 1.044 3 -bubbleSort() 100 12.728 13.172 13.564 3 -bubbleSort() 300 114.148 118.507 121.300 3 -insertionSort() 10 0.040 0.048 0.056 3 -insertionSort() 30 0.252 0.269 0.288 3 -insertionSort() 100 2.352 2.481 2.552 3 -insertionSort() 300 21.796 22.068 22.316 3 -shellSortClassic() 10 0.084 0.090 0.096 25 -shellSortClassic() 30 0.352 0.370 0.396 25 -shellSortClassic() 100 1.760 1.825 1.892 25 -shellSortClassic() 300 7.284 7.457 7.688 25 -shellSortKnuth() 10 0.092 0.100 0.108 25 -shellSortKnuth() 30 0.300 0.333 0.380 25 -shellSortKnuth() 100 1.372 1.437 1.544 25 -shellSortKnuth() 300 5.472 5.730 6.296 25 -shellSortTokuda() 10 0.068 0.076 0.088 25 -shellSortTokuda() 30 0.312 0.338 0.364 25 -shellSortTokuda() 100 1.564 1.627 1.744 25 -shellSortTokuda() 300 6.420 6.553 6.748 25 -combSort13() 10 0.156 0.165 0.188 25 -combSort13() 30 0.492 0.544 0.620 25 -combSort13() 100 2.128 2.291 2.676 25 -combSort13() 300 7.816 8.196 8.740 25 -combSort13m() 10 0.156 0.163 0.192 25 -combSort13m() 30 0.536 0.556 0.612 25 -combSort13m() 100 2.124 2.236 2.644 25 -combSort13m() 300 7.848 8.131 8.796 25 -combSort133() 10 0.076 0.087 0.104 25 -combSort133() 30 0.376 0.396 0.480 25 -combSort133() 100 1.828 1.982 2.276 25 -combSort133() 300 7.332 7.762 8.260 25 -combSort133m() 10 0.080 0.088 0.104 25 -combSort133m() 30 0.408 0.422 0.460 25 -combSort133m() 100 1.940 1.985 2.156 25 -combSort133m() 300 7.328 7.759 8.256 25 -quickSortMiddle() 10 0.072 0.096 0.124 25 -quickSortMiddle() 30 0.320 0.367 0.416 25 -quickSortMiddle() 100 1.412 1.566 1.996 25 -quickSortMiddle() 300 5.236 5.604 6.460 25 -quickSortMedian() 10 0.104 0.120 0.140 25 -quickSortMedian() 30 0.380 0.424 0.476 25 -quickSortMedian() 100 1.612 1.722 1.948 25 -quickSortMedian() 300 5.684 5.928 6.356 25 -quickSortMedianSwapped() 10 0.072 0.089 0.104 25 -quickSortMedianSwapped() 30 0.316 0.340 0.416 25 -quickSortMedianSwapped() 100 1.328 1.394 1.508 25 -quickSortMedianSwapped() 300 4.712 4.957 5.264 25 -qsort() 10 0.164 0.206 0.248 25 -qsort() 30 0.724 0.834 0.900 25 -qsort() 100 3.448 3.649 3.968 25 -qsort() 300 12.636 13.080 13.372 25 +bubbleSort() 10 0.096 0.115 0.140 3 +bubbleSort() 30 1.004 1.083 1.128 3 +bubbleSort() 100 12.076 12.773 13.428 3 +bubbleSort() 300 118.872 121.179 123.004 3 +insertionSort() 10 0.040 0.041 0.044 3 +insertionSort() 30 0.276 0.291 0.312 3 +insertionSort() 100 2.396 2.527 2.616 3 +insertionSort() 300 20.624 21.032 21.504 3 +selectionSort() 10 0.076 0.081 0.084 3 +selectionSort() 30 0.552 0.561 0.568 3 +selectionSort() 100 5.628 5.632 5.636 3 +selectionSort() 300 49.144 49.153 49.160 3 +shellSortClassic() 10 0.064 0.074 0.084 25 +shellSortClassic() 30 0.288 0.310 0.328 25 +shellSortClassic() 100 1.612 1.712 1.864 25 +shellSortClassic() 300 6.724 6.912 7.196 25 +shellSortKnuth() 10 0.092 0.101 0.116 25 +shellSortKnuth() 30 0.312 0.339 0.396 25 +shellSortKnuth() 100 1.368 1.445 1.568 25 +shellSortKnuth() 300 5.364 5.601 5.872 25 +shellSortTokuda() 10 0.064 0.076 0.088 25 +shellSortTokuda() 30 0.308 0.337 0.368 25 +shellSortTokuda() 100 1.556 1.634 1.688 25 +shellSortTokuda() 300 6.448 6.588 6.820 25 +combSort13() 10 0.156 0.165 0.192 25 +combSort13() 30 0.496 0.537 0.576 25 +combSort13() 100 1.988 2.209 2.648 25 +combSort13() 300 7.836 8.215 8.808 25 +combSort13m() 10 0.136 0.164 0.204 25 +combSort13m() 30 0.540 0.557 0.624 25 +combSort13m() 100 2.128 2.219 2.364 25 +combSort13m() 300 7.864 8.134 8.376 25 +combSort133() 10 0.080 0.086 0.104 25 +combSort133() 30 0.376 0.389 0.432 25 +combSort133() 100 1.824 1.996 2.404 25 +combSort133() 300 7.332 7.767 8.240 25 +combSort133m() 10 0.080 0.091 0.112 25 +combSort133m() 30 0.408 0.423 0.464 25 +combSort133m() 100 1.952 1.997 2.144 25 +combSort133m() 300 7.312 7.729 8.268 25 +quickSortMiddle() 10 0.084 0.099 0.116 25 +quickSortMiddle() 30 0.340 0.375 0.444 25 +quickSortMiddle() 100 1.444 1.619 1.924 25 +quickSortMiddle() 300 5.196 5.711 6.424 25 +quickSortMedian() 10 0.100 0.119 0.136 25 +quickSortMedian() 30 0.396 0.427 0.480 25 +quickSortMedian() 100 1.632 1.748 1.944 25 +quickSortMedian() 300 5.764 5.976 6.464 25 +quickSortMedianSwapped() 10 0.076 0.094 0.116 25 +quickSortMedianSwapped() 30 0.312 0.341 0.376 25 +quickSortMedianSwapped() 100 1.304 1.401 1.476 25 +quickSortMedianSwapped() 300 4.728 4.974 5.368 25 +qsort() 10 0.160 0.200 0.244 25 +qsort() 30 0.756 0.839 0.984 25 +qsort() 100 3.472 3.661 3.852 25 +qsort() 300 12.516 12.974 13.364 25 END diff --git a/examples/AutoBenchmark/nano.txt b/examples/AutoBenchmark/nano.txt index e697552..c3a2e5c 100644 --- a/examples/AutoBenchmark/nano.txt +++ b/examples/AutoBenchmark/nano.txt @@ -1,54 +1,58 @@ BENCHMARKS -bubbleSort() 10 0.088 0.101 0.128 3 -bubbleSort() 30 0.764 0.989 1.120 3 -bubbleSort() 100 10.732 11.841 12.816 3 -bubbleSort() 300 107.536 112.304 120.536 3 -insertionSort() 10 0.032 0.045 0.052 3 -insertionSort() 30 0.264 0.275 0.280 3 -insertionSort() 100 2.428 2.601 2.916 3 -insertionSort() 300 21.176 21.651 22.156 3 -shellSortClassic() 10 0.080 0.090 0.096 25 -shellSortClassic() 30 0.340 0.365 0.396 25 -shellSortClassic() 100 1.748 1.797 1.900 25 -shellSortClassic() 300 7.248 7.412 7.652 25 -shellSortKnuth() 10 0.092 0.102 0.124 25 -shellSortKnuth() 30 0.304 0.329 0.368 25 -shellSortKnuth() 100 1.392 1.443 1.512 25 -shellSortKnuth() 300 5.356 5.728 6.108 25 -shellSortTokuda() 10 0.064 0.074 0.080 25 -shellSortTokuda() 30 0.316 0.340 0.368 25 -shellSortTokuda() 100 1.548 1.631 1.684 25 -shellSortTokuda() 300 6.420 6.554 6.716 25 -combSort13() 10 0.156 0.163 0.196 25 -combSort13() 30 0.492 0.550 0.620 25 -combSort13() 100 1.968 2.220 2.608 25 -combSort13() 300 7.792 8.135 8.792 25 -combSort13m() 10 0.156 0.164 0.192 25 -combSort13m() 30 0.536 0.551 0.560 25 -combSort13m() 100 2.116 2.238 2.472 25 -combSort13m() 300 7.828 8.141 8.352 25 -combSort133() 10 0.080 0.085 0.108 25 -combSort133() 30 0.372 0.388 0.436 25 -combSort133() 100 1.816 1.950 2.272 25 -combSort133() 300 7.312 7.691 8.168 25 -combSort133m() 10 0.080 0.089 0.112 25 -combSort133m() 30 0.408 0.419 0.472 25 -combSort133m() 100 1.944 1.995 2.120 25 -combSort133m() 300 7.288 7.730 8.244 25 -quickSortMiddle() 10 0.084 0.096 0.108 25 -quickSortMiddle() 30 0.340 0.374 0.456 25 -quickSortMiddle() 100 1.408 1.558 1.920 25 -quickSortMiddle() 300 5.068 5.665 6.380 25 -quickSortMedian() 10 0.092 0.118 0.136 25 -quickSortMedian() 30 0.404 0.429 0.448 25 -quickSortMedian() 100 1.616 1.711 1.892 25 -quickSortMedian() 300 5.528 5.863 6.216 25 -quickSortMedianSwapped() 10 0.080 0.091 0.108 25 -quickSortMedianSwapped() 30 0.300 0.334 0.364 25 -quickSortMedianSwapped() 100 1.332 1.399 1.492 25 -quickSortMedianSwapped() 300 4.548 4.893 5.488 25 -qsort() 10 0.164 0.203 0.244 25 -qsort() 30 0.784 0.863 1.540 25 -qsort() 100 3.504 3.663 4.384 25 -qsort() 300 12.564 13.016 14.136 25 +bubbleSort() 10 0.084 0.107 0.132 3 +bubbleSort() 30 0.976 1.077 1.192 3 +bubbleSort() 100 11.836 12.735 13.648 3 +bubbleSort() 300 116.268 116.675 117.240 3 +insertionSort() 10 0.040 0.045 0.056 3 +insertionSort() 30 0.252 0.263 0.276 3 +insertionSort() 100 2.532 2.557 2.572 3 +insertionSort() 300 22.036 22.252 22.396 3 +selectionSort() 10 0.084 0.088 0.096 3 +selectionSort() 30 0.556 0.560 0.564 3 +selectionSort() 100 5.596 5.600 5.604 3 +selectionSort() 300 48.888 48.892 48.896 3 +shellSortClassic() 10 0.068 0.074 0.080 25 +shellSortClassic() 30 0.292 0.310 0.332 25 +shellSortClassic() 100 1.588 1.706 1.824 25 +shellSortClassic() 300 6.640 6.865 7.056 25 +shellSortKnuth() 10 0.092 0.101 0.112 25 +shellSortKnuth() 30 0.300 0.330 0.380 25 +shellSortKnuth() 100 1.340 1.450 1.652 25 +shellSortKnuth() 300 5.444 5.665 6.232 25 +shellSortTokuda() 10 0.068 0.075 0.084 25 +shellSortTokuda() 30 0.312 0.327 0.348 25 +shellSortTokuda() 100 1.556 1.614 1.700 25 +shellSortTokuda() 300 6.424 6.540 6.688 25 +combSort13() 10 0.128 0.160 0.204 25 +combSort13() 30 0.492 0.534 0.576 25 +combSort13() 100 2.120 2.214 2.640 25 +combSort13() 300 7.816 8.167 8.336 25 +combSort13m() 10 0.156 0.165 0.196 25 +combSort13m() 30 0.532 0.550 0.564 25 +combSort13m() 100 2.104 2.219 2.348 25 +combSort13m() 300 7.820 8.181 8.720 25 +combSort133() 10 0.080 0.086 0.108 25 +combSort133() 30 0.380 0.396 0.520 25 +combSort133() 100 1.808 1.944 2.288 25 +combSort133() 300 7.292 7.702 8.232 25 +combSort133m() 10 0.068 0.086 0.100 25 +combSort133m() 30 0.404 0.416 0.428 25 +combSort133m() 100 1.940 1.978 2.120 25 +combSort133m() 300 7.328 7.740 8.228 25 +quickSortMiddle() 10 0.076 0.096 0.112 25 +quickSortMiddle() 30 0.332 0.368 0.428 25 +quickSortMiddle() 100 1.436 1.568 1.808 25 +quickSortMiddle() 300 5.220 5.651 6.248 25 +quickSortMedian() 10 0.100 0.117 0.136 25 +quickSortMedian() 30 0.396 0.431 0.488 25 +quickSortMedian() 100 1.620 1.717 1.864 25 +quickSortMedian() 300 5.652 5.905 6.168 25 +quickSortMedianSwapped() 10 0.080 0.094 0.116 25 +quickSortMedianSwapped() 30 0.312 0.341 0.380 25 +quickSortMedianSwapped() 100 1.296 1.417 1.536 25 +quickSortMedianSwapped() 300 4.672 4.909 5.256 25 +qsort() 10 0.160 0.204 0.232 25 +qsort() 30 0.784 0.855 0.928 25 +qsort() 100 3.424 3.629 3.852 25 +qsort() 300 12.600 13.021 13.828 25 END diff --git a/examples/AutoBenchmark/samd.txt b/examples/AutoBenchmark/samd.txt index 987ef00..5af15f7 100644 --- a/examples/AutoBenchmark/samd.txt +++ b/examples/AutoBenchmark/samd.txt @@ -1,78 +1,83 @@ BENCHMARKS -bubbleSort() 10 0.027 0.033 0.039 3 -bubbleSort() 30 0.301 0.341 0.369 3 -bubbleSort() 100 3.820 3.915 4.085 3 -bubbleSort() 300 35.386 36.720 37.789 3 -bubbleSort() 1000 395.278 413.076 426.388 3 -insertionSort() 10 0.017 0.018 0.019 3 -insertionSort() 30 0.092 0.094 0.096 3 -insertionSort() 100 0.921 0.936 0.949 3 -insertionSort() 300 7.792 8.204 8.595 3 -insertionSort() 1000 85.992 87.954 89.588 3 -shellSortClassic() 10 0.020 0.022 0.023 20 -shellSortClassic() 30 0.080 0.085 0.091 20 -shellSortClassic() 100 0.400 0.416 0.429 20 -shellSortClassic() 300 1.652 1.700 1.743 20 -shellSortClassic() 1000 7.324 7.543 7.997 20 -shellSortClassic() 3000 27.330 27.936 28.955 20 -shellSortKnuth() 10 0.018 0.019 0.021 20 -shellSortKnuth() 30 0.058 0.066 0.075 20 -shellSortKnuth() 100 0.277 0.293 0.315 20 -shellSortKnuth() 300 1.095 1.150 1.201 20 -shellSortKnuth() 1000 4.858 5.078 5.289 20 -shellSortKnuth() 3000 18.500 19.490 21.899 20 -shellSortTokuda() 10 0.018 0.020 0.024 20 -shellSortTokuda() 30 0.076 0.082 0.089 20 -shellSortTokuda() 100 0.379 0.392 0.405 20 -shellSortTokuda() 300 1.539 1.558 1.581 20 -shellSortTokuda() 1000 6.588 6.689 6.790 20 -shellSortTokuda() 3000 23.939 24.188 24.369 20 -combSort13() 10 0.034 0.035 0.039 20 -combSort13() 30 0.110 0.120 0.146 20 -combSort13() 100 0.452 0.510 0.629 20 -combSort13() 300 1.776 1.848 1.991 20 -combSort13() 1000 7.914 8.194 8.913 20 -combSort13() 3000 28.918 29.611 30.992 20 -combSort13m() 10 0.034 0.036 0.040 20 -combSort13m() 30 0.122 0.125 0.135 20 -combSort13m() 100 0.482 0.512 0.561 20 -combSort13m() 300 1.780 1.872 1.998 20 -combSort13m() 1000 7.559 7.944 8.250 20 -combSort13m() 3000 27.915 28.631 29.931 20 -combSort133() 10 0.016 0.021 0.028 20 -combSort133() 30 0.085 0.091 0.124 20 -combSort133() 100 0.411 0.448 0.521 20 -combSort133() 300 1.652 1.754 1.862 20 -combSort133() 1000 7.287 7.939 10.002 20 -combSort133() 3000 26.152 27.346 32.219 20 -combSort133m() 10 0.021 0.022 0.026 20 -combSort133m() 30 0.096 0.099 0.108 20 -combSort133m() 100 0.444 0.456 0.488 20 -combSort133m() 300 1.649 1.752 1.869 20 -combSort133m() 1000 7.607 7.621 7.647 20 -combSort133m() 3000 26.167 26.992 28.210 20 -quickSortMiddle() 10 0.017 0.021 0.029 20 -quickSortMiddle() 30 0.067 0.075 0.083 20 -quickSortMiddle() 100 0.271 0.311 0.374 20 -quickSortMiddle() 300 1.014 1.065 1.144 20 -quickSortMiddle() 1000 3.930 4.237 4.630 20 -quickSortMiddle() 3000 13.359 14.362 16.093 20 -quickSortMedian() 10 0.022 0.026 0.029 20 -quickSortMedian() 30 0.079 0.087 0.096 20 -quickSortMedian() 100 0.334 0.348 0.377 20 -quickSortMedian() 300 1.102 1.167 1.236 20 -quickSortMedian() 1000 4.223 4.402 4.761 20 -quickSortMedian() 3000 14.000 14.555 15.527 20 -quickSortMedianSwapped() 10 0.016 0.020 0.024 20 -quickSortMedianSwapped() 30 0.064 0.071 0.080 20 -quickSortMedianSwapped() 100 0.268 0.282 0.302 20 -quickSortMedianSwapped() 300 0.933 0.982 1.056 20 -quickSortMedianSwapped() 1000 3.602 3.775 4.235 20 -quickSortMedianSwapped() 3000 12.240 12.711 13.209 20 -qsort() 10 0.039 0.050 0.058 20 -qsort() 30 0.187 0.206 0.254 20 -qsort() 100 0.818 0.861 0.918 20 -qsort() 300 2.939 3.071 3.309 20 -qsort() 1000 11.651 11.883 12.128 20 -qsort() 3000 39.859 40.299 40.952 20 +bubbleSort() 10 0.036 0.039 0.044 3 +bubbleSort() 30 0.315 0.357 0.387 3 +bubbleSort() 100 3.964 3.984 4.011 3 +bubbleSort() 300 35.300 36.967 38.476 3 +bubbleSort() 1000 425.463 429.557 431.644 3 +insertionSort() 10 0.012 0.014 0.016 3 +insertionSort() 30 0.087 0.095 0.108 3 +insertionSort() 100 0.834 0.880 0.948 3 +insertionSort() 300 7.820 8.132 8.320 3 +insertionSort() 1000 86.152 87.197 88.020 3 +selectionSort() 10 0.023 0.023 0.023 3 +selectionSort() 30 0.157 0.159 0.161 3 +selectionSort() 100 1.619 1.620 1.621 3 +selectionSort() 300 14.278 14.279 14.281 3 +selectionSort() 1000 157.534 157.547 157.568 3 +shellSortClassic() 10 0.014 0.016 0.018 20 +shellSortClassic() 30 0.058 0.064 0.071 20 +shellSortClassic() 100 0.334 0.349 0.380 20 +shellSortClassic() 300 1.363 1.405 1.460 20 +shellSortClassic() 1000 5.677 5.861 6.097 20 +shellSortClassic() 3000 21.989 22.452 23.069 20 +shellSortKnuth() 10 0.017 0.019 0.021 20 +shellSortKnuth() 30 0.062 0.067 0.074 20 +shellSortKnuth() 100 0.277 0.289 0.310 20 +shellSortKnuth() 300 1.102 1.153 1.206 20 +shellSortKnuth() 1000 4.867 5.111 5.437 20 +shellSortKnuth() 3000 18.550 19.448 20.784 20 +shellSortTokuda() 10 0.017 0.020 0.021 20 +shellSortTokuda() 30 0.076 0.081 0.085 20 +shellSortTokuda() 100 0.371 0.390 0.409 20 +shellSortTokuda() 300 1.514 1.556 1.596 20 +shellSortTokuda() 1000 6.580 6.673 6.773 20 +shellSortTokuda() 3000 23.952 24.187 24.643 20 +combSort13() 10 0.033 0.035 0.039 20 +combSort13() 30 0.109 0.118 0.124 20 +combSort13() 100 0.450 0.496 0.553 20 +combSort13() 300 1.777 1.859 1.987 20 +combSort13() 1000 7.915 8.180 8.935 20 +combSort13() 3000 28.934 29.661 31.978 20 +combSort13m() 10 0.034 0.035 0.041 20 +combSort13m() 30 0.121 0.124 0.137 20 +combSort13m() 100 0.481 0.512 0.560 20 +combSort13m() 300 1.784 1.882 1.991 20 +combSort13m() 1000 7.561 7.892 8.251 20 +combSort13m() 3000 27.894 28.483 28.964 20 +combSort133() 10 0.019 0.020 0.023 20 +combSort133() 30 0.086 0.090 0.102 20 +combSort133() 100 0.409 0.454 0.590 20 +combSort133() 300 1.652 1.764 1.868 20 +combSort133() 1000 7.282 7.897 8.620 20 +combSort133() 3000 26.165 26.989 28.205 20 +combSort133m() 10 0.021 0.021 0.023 20 +combSort133m() 30 0.096 0.097 0.101 20 +combSort133m() 100 0.446 0.454 0.487 20 +combSort133m() 300 1.653 1.752 1.870 20 +combSort133m() 1000 7.293 7.623 7.971 20 +combSort133m() 3000 26.179 27.649 32.205 20 +quickSortMiddle() 10 0.017 0.021 0.027 20 +quickSortMiddle() 30 0.062 0.073 0.089 20 +quickSortMiddle() 100 0.283 0.315 0.383 20 +quickSortMiddle() 300 1.005 1.077 1.182 20 +quickSortMiddle() 1000 3.864 4.211 4.759 20 +quickSortMiddle() 3000 13.376 14.031 14.748 20 +quickSortMedian() 10 0.022 0.026 0.031 20 +quickSortMedian() 30 0.077 0.088 0.100 20 +quickSortMedian() 100 0.328 0.344 0.369 20 +quickSortMedian() 300 1.106 1.161 1.227 20 +quickSortMedian() 1000 4.233 4.343 4.525 20 +quickSortMedian() 3000 14.120 14.455 15.235 20 +quickSortMedianSwapped() 10 0.017 0.020 0.023 20 +quickSortMedianSwapped() 30 0.064 0.070 0.077 20 +quickSortMedianSwapped() 100 0.264 0.285 0.315 20 +quickSortMedianSwapped() 300 0.939 1.001 1.065 20 +quickSortMedianSwapped() 1000 3.631 3.783 4.090 20 +quickSortMedianSwapped() 3000 12.076 12.630 13.381 20 +qsort() 10 0.041 0.054 0.068 20 +qsort() 30 0.189 0.213 0.249 20 +qsort() 100 0.827 0.886 0.921 20 +qsort() 300 3.118 3.215 3.375 20 +qsort() 1000 12.392 12.678 12.994 20 +qsort() 3000 42.268 42.791 43.244 20 END diff --git a/examples/AutoBenchmark/stm32.txt b/examples/AutoBenchmark/stm32.txt index 1b671cd..a3c6365 100644 --- a/examples/AutoBenchmark/stm32.txt +++ b/examples/AutoBenchmark/stm32.txt @@ -1,78 +1,83 @@ BENCHMARKS -bubbleSort() 10 0.018 0.019 0.020 3 -bubbleSort() 30 0.189 0.200 0.213 3 -bubbleSort() 100 1.946 2.056 2.158 3 -bubbleSort() 300 18.720 19.174 19.936 3 -bubbleSort() 1000 226.916 229.211 231.662 3 -insertionSort() 10 0.008 0.009 0.010 3 -insertionSort() 30 0.042 0.053 0.061 3 -insertionSort() 100 0.495 0.512 0.530 3 -insertionSort() 300 4.453 4.584 4.781 3 -insertionSort() 1000 47.177 49.112 51.649 3 -shellSortClassic() 10 0.017 0.018 0.019 20 -shellSortClassic() 30 0.069 0.074 0.080 20 -shellSortClassic() 100 0.349 0.363 0.382 20 -shellSortClassic() 300 1.438 1.492 1.539 20 -shellSortClassic() 1000 6.245 6.411 6.681 20 -shellSortClassic() 3000 23.029 23.660 24.031 20 -shellSortKnuth() 10 0.011 0.014 0.016 20 -shellSortKnuth() 30 0.052 0.059 0.063 20 -shellSortKnuth() 100 0.269 0.290 0.316 20 -shellSortKnuth() 300 1.105 1.182 1.290 20 -shellSortKnuth() 1000 5.196 5.308 5.464 20 -shellSortKnuth() 3000 19.265 20.425 22.070 20 -shellSortTokuda() 10 0.010 0.011 0.013 20 -shellSortTokuda() 30 0.044 0.048 0.060 20 -shellSortTokuda() 100 0.220 0.228 0.238 20 -shellSortTokuda() 300 0.882 0.915 0.941 20 -shellSortTokuda() 1000 3.830 3.888 3.934 20 -shellSortTokuda() 3000 13.976 14.116 14.271 20 +bubbleSort() 10 0.013 0.018 0.025 3 +bubbleSort() 30 0.128 0.161 0.214 3 +bubbleSort() 100 2.064 2.105 2.186 3 +bubbleSort() 300 19.574 19.955 20.358 3 +bubbleSort() 1000 222.869 225.639 229.515 3 +insertionSort() 10 0.008 0.010 0.011 3 +insertionSort() 30 0.051 0.054 0.057 3 +insertionSort() 100 0.466 0.495 0.544 3 +insertionSort() 300 4.402 4.486 4.636 3 +insertionSort() 1000 47.204 48.616 49.785 3 +selectionSort() 10 0.017 0.017 0.017 3 +selectionSort() 30 0.115 0.116 0.116 3 +selectionSort() 100 1.165 1.167 1.169 3 +selectionSort() 300 10.196 10.197 10.200 3 +selectionSort() 1000 112.178 112.180 112.183 3 +shellSortClassic() 10 0.013 0.014 0.015 20 +shellSortClassic() 30 0.055 0.058 0.064 20 +shellSortClassic() 100 0.297 0.324 0.362 20 +shellSortClassic() 300 1.229 1.284 1.337 20 +shellSortClassic() 1000 5.292 5.427 5.557 20 +shellSortClassic() 3000 20.049 20.852 21.631 20 +shellSortKnuth() 10 0.012 0.014 0.019 20 +shellSortKnuth() 30 0.054 0.059 0.068 20 +shellSortKnuth() 100 0.287 0.305 0.331 20 +shellSortKnuth() 300 1.168 1.236 1.322 20 +shellSortKnuth() 1000 5.335 5.604 6.061 20 +shellSortKnuth() 3000 20.874 21.566 22.651 20 +shellSortTokuda() 10 0.010 0.011 0.012 20 +shellSortTokuda() 30 0.042 0.047 0.051 20 +shellSortTokuda() 100 0.217 0.226 0.235 20 +shellSortTokuda() 300 0.874 0.901 0.927 20 +shellSortTokuda() 1000 3.816 3.904 3.968 20 +shellSortTokuda() 3000 14.045 14.199 14.364 20 combSort13() 10 0.018 0.019 0.022 20 -combSort13() 30 0.083 0.090 0.096 20 -combSort13() 100 0.404 0.452 0.517 20 -combSort13() 300 1.725 1.794 1.946 20 -combSort13() 1000 7.527 8.182 9.709 20 -combSort13() 3000 29.074 30.001 33.435 20 -combSort13m() 10 0.018 0.020 0.027 20 -combSort13m() 30 0.090 0.091 0.100 20 -combSort13m() 100 0.426 0.446 0.500 20 -combSort13m() 300 1.675 1.715 1.785 20 -combSort13m() 1000 7.646 7.666 7.998 20 -combSort13m() 3000 27.127 27.604 28.185 20 -combSort133() 10 0.017 0.018 0.021 20 -combSort133() 30 0.083 0.084 0.088 20 -combSort133() 100 0.397 0.429 0.503 20 -combSort133() 300 1.600 1.685 1.708 20 -combSort133() 1000 7.062 7.692 10.905 20 -combSort133() 3000 25.376 26.113 27.477 20 -combSort133m() 10 0.018 0.018 0.022 20 -combSort133m() 30 0.091 0.092 0.101 20 -combSort133m() 100 0.429 0.434 0.465 20 -combSort133m() 300 1.603 1.702 1.814 20 -combSort133m() 1000 7.407 7.481 8.457 20 -combSort133m() 3000 25.381 26.431 27.481 20 -quickSortMiddle() 10 0.015 0.018 0.021 20 -quickSortMiddle() 30 0.060 0.069 0.083 20 -quickSortMiddle() 100 0.264 0.292 0.375 20 -quickSortMiddle() 300 0.930 1.041 1.191 20 -quickSortMiddle() 1000 3.790 4.061 4.597 20 -quickSortMiddle() 3000 12.711 13.649 14.869 20 -quickSortMedian() 10 0.018 0.021 0.023 20 -quickSortMedian() 30 0.069 0.078 0.087 20 -quickSortMedian() 100 0.300 0.314 0.333 20 -quickSortMedian() 300 1.041 1.120 1.186 20 -quickSortMedian() 1000 4.092 4.218 4.513 20 -quickSortMedian() 3000 13.901 14.402 15.927 20 -quickSortMedianSwapped() 10 0.012 0.014 0.017 20 -quickSortMedianSwapped() 30 0.048 0.054 0.061 20 -quickSortMedianSwapped() 100 0.218 0.232 0.276 20 -quickSortMedianSwapped() 300 0.777 0.831 0.874 20 -quickSortMedianSwapped() 1000 3.078 3.249 3.543 20 -quickSortMedianSwapped() 3000 10.745 11.240 11.706 20 -qsort() 10 0.024 0.032 0.042 20 -qsort() 30 0.113 0.134 0.209 20 -qsort() 100 0.539 0.573 0.627 20 -qsort() 300 2.043 2.124 2.266 20 -qsort() 1000 8.134 8.337 8.647 20 -qsort() 3000 28.261 28.772 29.454 20 +combSort13() 30 0.081 0.087 0.104 20 +combSort13() 100 0.428 0.442 0.498 20 +combSort13() 300 1.674 1.770 1.886 20 +combSort13() 1000 7.301 7.895 8.699 20 +combSort13() 3000 28.178 28.862 30.275 20 +combSort13m() 10 0.017 0.018 0.025 20 +combSort13m() 30 0.087 0.087 0.092 20 +combSort13m() 100 0.409 0.430 0.448 20 +combSort13m() 300 1.611 1.697 1.814 20 +combSort13m() 1000 7.009 7.380 7.683 20 +combSort13m() 3000 26.049 26.657 28.064 20 +combSort133() 10 0.017 0.018 0.022 20 +combSort133() 30 0.082 0.085 0.107 20 +combSort133() 100 0.394 0.417 0.468 20 +combSort133() 300 1.585 1.649 1.693 20 +combSort133() 1000 7.000 7.630 8.396 20 +combSort133() 3000 25.152 26.148 28.293 20 +combSort133m() 10 0.014 0.019 0.021 20 +combSort133m() 30 0.087 0.089 0.098 20 +combSort133m() 100 0.413 0.419 0.448 20 +combSort133m() 300 1.535 1.619 1.643 20 +combSort133m() 1000 6.783 7.151 7.787 20 +combSort133m() 3000 24.373 25.380 27.393 20 +quickSortMiddle() 10 0.016 0.019 0.033 20 +quickSortMiddle() 30 0.059 0.067 0.079 20 +quickSortMiddle() 100 0.259 0.278 0.301 20 +quickSortMiddle() 300 0.926 0.990 1.096 20 +quickSortMiddle() 1000 3.620 3.835 4.171 20 +quickSortMiddle() 3000 12.483 13.145 13.883 20 +quickSortMedian() 10 0.018 0.020 0.026 20 +quickSortMedian() 30 0.071 0.076 0.079 20 +quickSortMedian() 100 0.289 0.311 0.345 20 +quickSortMedian() 300 1.054 1.101 1.167 20 +quickSortMedian() 1000 4.050 4.212 4.573 20 +quickSortMedian() 3000 13.888 14.381 15.341 20 +quickSortMedianSwapped() 10 0.012 0.015 0.018 20 +quickSortMedianSwapped() 30 0.051 0.056 0.061 20 +quickSortMedianSwapped() 100 0.217 0.228 0.243 20 +quickSortMedianSwapped() 300 0.788 0.836 0.909 20 +quickSortMedianSwapped() 1000 3.162 3.285 3.619 20 +quickSortMedianSwapped() 3000 10.776 11.265 12.538 20 +qsort() 10 0.025 0.034 0.047 20 +qsort() 30 0.123 0.149 0.317 20 +qsort() 100 0.566 0.615 0.836 20 +qsort() 300 2.173 2.221 2.313 20 +qsort() 1000 8.652 8.921 9.368 20 +qsort() 3000 30.092 30.627 31.322 20 END diff --git a/examples/AutoBenchmark/teensy32.txt b/examples/AutoBenchmark/teensy32.txt index ce2d78c..ece77a7 100644 --- a/examples/AutoBenchmark/teensy32.txt +++ b/examples/AutoBenchmark/teensy32.txt @@ -1,78 +1,83 @@ BENCHMARKS -bubbleSort() 10 0.008 0.008 0.008 3 -bubbleSort() 30 0.077 0.077 0.077 3 -bubbleSort() 100 0.870 0.957 1.002 3 -bubbleSort() 300 8.402 8.534 8.751 3 -bubbleSort() 1000 95.968 97.649 98.793 3 -insertionSort() 10 0.005 0.006 0.006 3 -insertionSort() 30 0.041 0.044 0.046 3 -insertionSort() 100 0.371 0.392 0.407 3 -insertionSort() 300 3.202 3.410 3.659 3 -insertionSort() 1000 35.557 36.368 36.792 3 -shellSortClassic() 10 0.008 0.009 0.011 20 -shellSortClassic() 30 0.032 0.034 0.037 20 -shellSortClassic() 100 0.160 0.168 0.175 20 -shellSortClassic() 300 0.675 0.688 0.714 20 -shellSortClassic() 1000 2.951 3.021 3.175 20 -shellSortClassic() 3000 10.862 11.131 11.448 20 +bubbleSort() 10 0.008 0.009 0.010 3 +bubbleSort() 30 0.073 0.079 0.082 3 +bubbleSort() 100 0.743 0.824 0.940 3 +bubbleSort() 300 8.002 8.469 8.977 3 +bubbleSort() 1000 94.984 98.471 101.370 3 +insertionSort() 10 0.006 0.006 0.007 3 +insertionSort() 30 0.036 0.041 0.049 3 +insertionSort() 100 0.385 0.394 0.402 3 +insertionSort() 300 3.300 3.390 3.485 3 +insertionSort() 1000 36.376 36.820 37.584 3 +selectionSort() 10 0.008 0.008 0.008 3 +selectionSort() 30 0.057 0.057 0.058 3 +selectionSort() 100 0.589 0.590 0.590 3 +selectionSort() 300 5.212 5.215 5.218 3 +selectionSort() 1000 57.556 57.558 57.560 3 +shellSortClassic() 10 0.006 0.007 0.009 20 +shellSortClassic() 30 0.027 0.029 0.031 20 +shellSortClassic() 100 0.150 0.162 0.173 20 +shellSortClassic() 300 0.630 0.648 0.671 20 +shellSortClassic() 1000 2.651 2.712 2.809 20 +shellSortClassic() 3000 9.971 10.394 10.906 20 shellSortKnuth() 10 0.005 0.006 0.008 20 -shellSortKnuth() 30 0.024 0.027 0.030 20 -shellSortKnuth() 100 0.123 0.131 0.141 20 -shellSortKnuth() 300 0.500 0.524 0.552 20 -shellSortKnuth() 1000 2.241 2.326 2.422 20 -shellSortKnuth() 3000 8.553 8.970 9.189 20 +shellSortKnuth() 30 0.025 0.027 0.032 20 +shellSortKnuth() 100 0.123 0.133 0.141 20 +shellSortKnuth() 300 0.511 0.531 0.552 20 +shellSortKnuth() 1000 2.244 2.339 2.490 20 +shellSortKnuth() 3000 8.658 8.903 9.199 20 shellSortTokuda() 10 0.006 0.007 0.008 20 -shellSortTokuda() 30 0.027 0.028 0.030 20 -shellSortTokuda() 100 0.133 0.137 0.142 20 -shellSortTokuda() 300 0.523 0.542 0.558 20 -shellSortTokuda() 1000 2.283 2.311 2.334 20 -shellSortTokuda() 3000 8.296 8.349 8.430 20 -combSort13() 10 0.006 0.008 0.009 20 +shellSortTokuda() 30 0.026 0.028 0.030 20 +shellSortTokuda() 100 0.130 0.136 0.142 20 +shellSortTokuda() 300 0.529 0.539 0.547 20 +shellSortTokuda() 1000 2.256 2.314 2.364 20 +shellSortTokuda() 3000 8.287 8.366 8.440 20 +combSort13() 10 0.007 0.008 0.010 20 combSort13() 30 0.033 0.036 0.039 20 -combSort13() 100 0.176 0.179 0.192 20 -combSort13() 300 0.686 0.716 0.812 20 -combSort13() 1000 3.134 3.253 3.547 20 -combSort13() 3000 11.534 11.911 12.757 20 -combSort13m() 10 0.007 0.009 0.010 20 -combSort13m() 30 0.037 0.038 0.042 20 -combSort13m() 100 0.176 0.185 0.206 20 -combSort13m() 300 0.688 0.719 0.772 20 -combSort13m() 1000 2.993 3.139 3.267 20 -combSort13m() 3000 11.123 11.372 11.545 20 +combSort13() 100 0.175 0.182 0.212 20 +combSort13() 300 0.688 0.722 0.770 20 +combSort13() 1000 3.134 3.233 3.414 20 +combSort13() 3000 11.533 11.887 12.768 20 +combSort13m() 10 0.008 0.008 0.010 20 +combSort13m() 30 0.037 0.038 0.040 20 +combSort13m() 100 0.176 0.186 0.220 20 +combSort13m() 300 0.689 0.725 0.770 20 +combSort13m() 1000 3.128 3.139 3.272 20 +combSort13m() 3000 11.124 11.431 11.545 20 combSort133() 10 0.007 0.008 0.009 20 -combSort133() 30 0.034 0.035 0.039 20 -combSort133() 100 0.164 0.170 0.187 20 -combSort133() 300 0.660 0.695 0.742 20 -combSort133() 1000 2.905 3.169 3.458 20 -combSort133() 3000 10.441 10.965 13.720 20 -combSort133m() 10 0.007 0.008 0.009 20 +combSort133() 30 0.034 0.035 0.035 20 +combSort133() 100 0.163 0.174 0.207 20 +combSort133() 300 0.660 0.698 0.745 20 +combSort133() 1000 2.904 3.101 3.319 20 +combSort133() 3000 10.451 10.902 12.078 20 +combSort133m() 10 0.007 0.008 0.010 20 combSort133m() 30 0.037 0.038 0.042 20 -combSort133m() 100 0.176 0.180 0.198 20 -combSort133m() 300 0.661 0.702 0.745 20 -combSort133m() 1000 2.899 3.016 3.055 20 -combSort133m() 3000 10.452 10.884 12.091 20 +combSort133m() 100 0.176 0.180 0.191 20 +combSort133m() 300 0.699 0.710 0.746 20 +combSort133m() 1000 2.908 3.030 3.050 20 +combSort133m() 3000 10.448 10.801 11.276 20 quickSortMiddle() 10 0.006 0.007 0.009 20 -quickSortMiddle() 30 0.024 0.026 0.033 20 -quickSortMiddle() 100 0.096 0.110 0.121 20 -quickSortMiddle() 300 0.366 0.392 0.427 20 -quickSortMiddle() 1000 1.382 1.541 1.693 20 -quickSortMiddle() 3000 4.862 5.275 5.889 20 -quickSortMedian() 10 0.007 0.009 0.011 20 -quickSortMedian() 30 0.027 0.030 0.033 20 -quickSortMedian() 100 0.114 0.122 0.132 20 -quickSortMedian() 300 0.396 0.414 0.444 20 -quickSortMedian() 1000 1.549 1.605 1.698 20 -quickSortMedian() 3000 5.084 5.358 6.104 20 -quickSortMedianSwapped() 10 0.006 0.007 0.008 20 -quickSortMedianSwapped() 30 0.023 0.025 0.028 20 -quickSortMedianSwapped() 100 0.095 0.102 0.118 20 -quickSortMedianSwapped() 300 0.337 0.364 0.400 20 -quickSortMedianSwapped() 1000 1.334 1.402 1.518 20 -quickSortMedianSwapped() 3000 4.577 4.717 4.871 20 -qsort() 10 0.015 0.017 0.021 20 -qsort() 30 0.066 0.072 0.081 20 -qsort() 100 0.293 0.313 0.324 20 -qsort() 300 1.110 1.154 1.190 20 -qsort() 1000 4.524 4.585 4.731 20 -qsort() 3000 15.482 15.785 16.319 20 +quickSortMiddle() 30 0.023 0.026 0.028 20 +quickSortMiddle() 100 0.095 0.109 0.140 20 +quickSortMiddle() 300 0.353 0.388 0.423 20 +quickSortMiddle() 1000 1.424 1.520 1.806 20 +quickSortMiddle() 3000 4.957 5.278 5.846 20 +quickSortMedian() 10 0.007 0.009 0.010 20 +quickSortMedian() 30 0.028 0.030 0.032 20 +quickSortMedian() 100 0.114 0.122 0.134 20 +quickSortMedian() 300 0.399 0.423 0.456 20 +quickSortMedian() 1000 1.520 1.590 1.663 20 +quickSortMedian() 3000 5.180 5.387 5.604 20 +quickSortMedianSwapped() 10 0.006 0.007 0.009 20 +quickSortMedianSwapped() 30 0.022 0.025 0.028 20 +quickSortMedianSwapped() 100 0.094 0.100 0.108 20 +quickSortMedianSwapped() 300 0.345 0.365 0.381 20 +quickSortMedianSwapped() 1000 1.341 1.412 1.662 20 +quickSortMedianSwapped() 3000 4.559 4.752 5.080 20 +qsort() 10 0.013 0.017 0.022 20 +qsort() 30 0.067 0.073 0.101 20 +qsort() 100 0.301 0.315 0.335 20 +qsort() 300 1.135 1.156 1.197 20 +qsort() 1000 4.474 4.576 4.722 20 +qsort() 3000 15.456 15.732 16.127 20 END From 9102e4ffb1dfde0a446cf828865103e0f06d4c4b Mon Sep 17 00:00:00 2001 From: Brian Park Date: Thu, 5 Aug 2021 14:52:53 -0700 Subject: [PATCH 05/12] README.md: Add 'Bugs and Limitations' section --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/README.md b/README.md index 15fbff3..df57a48 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ versions which take a custom comparator. * [Hardware](#Hardware) * [Tool Chain](#ToolChain) * [Operating System](#OperatingSystem) +* [Bugs and Limitations](#BugsAndLimitations) * [Alternative Libraries](#AlternativeLibraries) * [License](#License) * [Feedback and Support](#FeedbackAndSupport) @@ -493,6 +494,43 @@ I use Ubuntu 20.04 for the vast majority of my development. I expect that the library will work fine under MacOS and Windows, but I have not explicitly tested them. + +## Bugs and Limitations + +* The number of elements `n` of the input `data` array is of type `uint16_t`, + which is exactly 2 bytes on all platforms. + * This means that the maximum number of elements is 65535. This should be + large enough for almost all applications on Arduino platforms, because + often the RAM size is limited. + * Using a fixed `uint16_t` means that the edge case behavior of these + algorithms are consistency across all platforms. + * Certain implementation choices and optimizations can be made if we know + that `n` cannot exceed a bounded value. For example, the + `shellSortTokuda()` function can use a pre-generated sequence of gaps + which is a reasonable size because it only needs to go up to 65535. + * The alternative was to use the `size_t` type whose size is dependent on + the platform. On 8-bit processors, `size_t` is 2 bytes; on 32-bit + processors `size_t` is 4 bytes; and on 64-bit processors, `size_t` is 8 + bytes. However, I did not want to worry about edge case behavior of some + of these algorithms for extremely large values of `n`. + * There is also a common assumption that the natural-sized `int` (and + `unsigned int`) type is faster on their respective platforms . My actual + benchmarking experience suggests that this is not always true. Sometimes + it is, and sometimes it isn't, and the difference between using a + `uint16_t` versus `uint32_t` on a 32-bit processor is probably not as + great as choosing a better sorting algorithm. +* No hybrid sorting algorithms (yet). + * Different sorting algorithms are more efficient at different ranges of + `N`. So hybrid algorithms will use different sorting algorithms at + different points in their iteration. An example is the + [Introsort](https://en.wikipedia.org/wiki/Introsort) which uses Quick + Sort, then switches to Heap Sort when the recursion depth becomes too + high, then switches to Insertion Sort when `N` is below a threshold. + * This library currently does not implement such sorting algorithms, partly + because they are more difficult to write and validate, and partly because + these hybrid algorithms will inevitably consume more flash memory, which + is usually a scarce resource in embedded environments. + ## Alternative Libraries From df0f30a04885b760d5b4305cd076536953252dd0 Mon Sep 17 00:00:00 2001 From: Brian Park Date: Thu, 5 Aug 2021 14:55:36 -0700 Subject: [PATCH 06/12] README.md: Fix short descriptions of combSortXxx() --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index df57a48..5d138a1 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,10 @@ using C++11 templates. Supports the following algorithms: * `shellSortTokuda()`: gap factor 2.25 * Comb Sort * `combSort13()`: gap factor 1.3 (13/10) - * `combSort13m()`: gap factor 1.3, modified for gap 8 and 9 (recommended - for 32-bit processors + * `combSort13m()`: gap factor 1.3, modified for gaps 9 and 10 (recommended + for 32-bit processors) * `combSort133()`: gap factor 1.33 (4/3) (recommended for 8-bit processors) - * `combSort133m()`: gap factor 1.33 + * `combSort133m()`: gap factor 1.33, modified for gaps 9 and 10 * Quick Sort * `quickSortMiddle()`: pivot on middle element (recommended) * `quickSortMedian()`: pivot on median of low, mid, high From 078f2b9fe311691850ba6998fde78522273afa5c Mon Sep 17 00:00:00 2001 From: Brian Park Date: Thu, 5 Aug 2021 16:09:22 -0700 Subject: [PATCH 07/12] src/selectionSort.h: Start inner loop to find min element at 'j = i', saving 12 bytes of flash on AVR --- README.md | 6 +++--- examples/MemoryBenchmark/README.md | 10 +++++----- examples/MemoryBenchmark/micro.txt | 2 +- examples/MemoryBenchmark/nano.txt | 2 +- examples/MemoryBenchmark/samd.txt | 2 +- examples/MemoryBenchmark/stm32.txt | 2 +- examples/MemoryBenchmark/teensy32.txt | 2 +- src/ace_sorting/selectionSort.h | 16 ++++++++++++++-- 8 files changed, 27 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 5d138a1..cb8b086 100644 --- a/README.md +++ b/README.md @@ -330,9 +330,9 @@ The full details of flash and static memory consumptions are given in |----------------------------------------+--------------+-------------| | bubbleSort() | 1110/ 214 | 44/ 0 | | insertionSort() | 1126/ 214 | 60/ 0 | -| selectionSort() | 1166/ 214 | 100/ 0 | +| selectionSort() | 1154/ 214 | 88/ 0 | |----------------------------------------+--------------+-------------| -| shellSortClassic() | 1164/ 214 | 98/ 0 | +| shellSortClassic() | 1162/ 214 | 96/ 0 | | shellSortKnuth() | 1208/ 214 | 142/ 0 | | shellSortTokuda() | 1248/ 240 | 182/ 26 | |----------------------------------------+--------------+-------------| @@ -361,7 +361,7 @@ The full details of flash and static memory consumptions are given in | insertionSort() | 257164/26976 | 64/ 0 | | selectionSort() | 257180/26976 | 80/ 0 | |----------------------------------------+--------------+-------------| -| shellSortClassic() | 257196/26976 | 96/ 0 | +| shellSortClassic() | 257180/26976 | 80/ 0 | | shellSortKnuth() | 257212/26976 | 112/ 0 | | shellSortTokuda() | 257256/27004 | 156/ 28 | |----------------------------------------+--------------+-------------| diff --git a/examples/MemoryBenchmark/README.md b/examples/MemoryBenchmark/README.md index 47eff8c..7b88d11 100644 --- a/examples/MemoryBenchmark/README.md +++ b/examples/MemoryBenchmark/README.md @@ -53,7 +53,7 @@ ASCII table. |----------------------------------------+--------------+-------------| | bubbleSort() | 1110/ 214 | 44/ 0 | | insertionSort() | 1126/ 214 | 60/ 0 | -| selectionSort() | 1166/ 214 | 100/ 0 | +| selectionSort() | 1154/ 214 | 88/ 0 | |----------------------------------------+--------------+-------------| | shellSortClassic() | 1162/ 214 | 96/ 0 | | shellSortKnuth() | 1208/ 214 | 142/ 0 | @@ -87,7 +87,7 @@ ASCII table. |----------------------------------------+--------------+-------------| | bubbleSort() | 4104/ 354 | 44/ 0 | | insertionSort() | 4120/ 354 | 60/ 0 | -| selectionSort() | 4160/ 354 | 100/ 0 | +| selectionSort() | 4148/ 354 | 88/ 0 | |----------------------------------------+--------------+-------------| | shellSortClassic() | 4156/ 354 | 96/ 0 | | shellSortKnuth() | 4202/ 354 | 142/ 0 | @@ -121,7 +121,7 @@ ASCII table. |----------------------------------------+--------------+-------------| | bubbleSort() | 10696/ 0 | 32/ 0 | | insertionSort() | 10712/ 0 | 48/ 0 | -| selectionSort() | 10744/ 0 | 80/ 0 | +| selectionSort() | 10740/ 0 | 76/ 0 | |----------------------------------------+--------------+-------------| | shellSortClassic() | 10720/ 0 | 56/ 0 | | shellSortKnuth() | 10736/ 0 | 72/ 0 | @@ -157,7 +157,7 @@ ASCII table. |----------------------------------------+--------------+-------------| | bubbleSort() | 26856/ 3844 | 36/ 0 | | insertionSort() | 26864/ 3844 | 44/ 0 | -| selectionSort() | 26884/ 3844 | 64/ 0 | +| selectionSort() | 26900/ 3844 | 80/ 0 | |----------------------------------------+--------------+-------------| | shellSortClassic() | 26884/ 3844 | 64/ 0 | | shellSortKnuth() | 26900/ 3844 | 80/ 0 | @@ -263,7 +263,7 @@ usage by objects. |----------------------------------------+--------------+-------------| | bubbleSort() | 7816/ 3256 | 28/ 0 | | insertionSort() | 7844/ 3256 | 56/ 0 | -| selectionSort() | 7864/ 3256 | 76/ 0 | +| selectionSort() | 7852/ 3256 | 64/ 0 | |----------------------------------------+--------------+-------------| | shellSortClassic() | 7868/ 3256 | 80/ 0 | | shellSortKnuth() | 7880/ 3256 | 92/ 0 | diff --git a/examples/MemoryBenchmark/micro.txt b/examples/MemoryBenchmark/micro.txt index 77378a2..ee3ebeb 100644 --- a/examples/MemoryBenchmark/micro.txt +++ b/examples/MemoryBenchmark/micro.txt @@ -1,7 +1,7 @@ 0 4060 28672 354 2560 1 4104 28672 354 2560 2 4120 28672 354 2560 -3 4160 28672 354 2560 +3 4148 28672 354 2560 4 4156 28672 354 2560 5 4202 28672 354 2560 6 4242 28672 380 2560 diff --git a/examples/MemoryBenchmark/nano.txt b/examples/MemoryBenchmark/nano.txt index 4dc5bd4..4c6cc25 100644 --- a/examples/MemoryBenchmark/nano.txt +++ b/examples/MemoryBenchmark/nano.txt @@ -1,7 +1,7 @@ 0 1066 30720 214 2048 1 1110 30720 214 2048 2 1126 30720 214 2048 -3 1166 30720 214 2048 +3 1154 30720 214 2048 4 1162 30720 214 2048 5 1208 30720 214 2048 6 1248 30720 240 2048 diff --git a/examples/MemoryBenchmark/samd.txt b/examples/MemoryBenchmark/samd.txt index bb07d2a..3677945 100644 --- a/examples/MemoryBenchmark/samd.txt +++ b/examples/MemoryBenchmark/samd.txt @@ -1,7 +1,7 @@ 0 10664 262144 1 10696 262144 2 10712 262144 -3 10744 262144 +3 10740 262144 4 10720 262144 5 10736 262144 6 10836 262144 diff --git a/examples/MemoryBenchmark/stm32.txt b/examples/MemoryBenchmark/stm32.txt index ae54955..a564471 100644 --- a/examples/MemoryBenchmark/stm32.txt +++ b/examples/MemoryBenchmark/stm32.txt @@ -1,7 +1,7 @@ 0 26820 131072 3844 20480 1 26856 131072 3844 20480 2 26864 131072 3844 20480 -3 26884 131072 3844 20480 +3 26900 131072 3844 20480 4 26884 131072 3844 20480 5 26900 131072 3844 20480 6 26956 131072 3844 20480 diff --git a/examples/MemoryBenchmark/teensy32.txt b/examples/MemoryBenchmark/teensy32.txt index 57c4508..3141051 100644 --- a/examples/MemoryBenchmark/teensy32.txt +++ b/examples/MemoryBenchmark/teensy32.txt @@ -1,7 +1,7 @@ 0 7788 262144 3256 65536 1 7816 262144 3256 65536 2 7844 262144 3256 65536 -3 7864 262144 3256 65536 +3 7852 262144 3256 65536 4 7868 262144 3256 65536 5 7880 262144 3256 65536 6 7976 262144 3256 65536 diff --git a/src/ace_sorting/selectionSort.h b/src/ace_sorting/selectionSort.h index a96f716..7d47ce2 100644 --- a/src/ace_sorting/selectionSort.h +++ b/src/ace_sorting/selectionSort.h @@ -44,16 +44,28 @@ namespace ace_sorting { template void selectionSort(T data[], uint16_t n) { for (uint16_t i = 0; i < n; i++) { - // Find the smallest element + + // Loop to find the smallest element. uint16_t iSmallest = i; T smallest = data[i]; - for (uint16_t j = i + 1; j < n; j++) { + + // Starting the loop with 'j = i + 1' increases flash usage on AVR by 12 + // bytes. But it does not reduce the execution time signficantly, because + // the (i + 1) will be done anyway by the j++ in the loop. So the only thing + // we save is a single redundant 'smallest < smallest' comparison. + for (uint16_t j = i; j < n; j++) { if (data[j] < smallest) { iSmallest = j; smallest = data[j]; } } + // This extra check (i != iSmallest) is not really necessary, because if the + // first element was already the smallest, it would swap the value back into + // itself. However, the one situation where Selection Sort *might* be used + // over Insertion Sort is when the write operation is far more expensive + // than a read operation. So this test preserves that advantage of the + // Selection Sort, by avoiding doing an unnecessary swap. if (i != iSmallest) { swap(data[i], data[iSmallest]); } From 5b0cca342e7ace26957ca3d23d853caff3d50e10 Mon Sep 17 00:00:00 2001 From: Brian Park Date: Thu, 5 Aug 2021 19:06:37 -0700 Subject: [PATCH 08/12] README.md: Tighten up prose in the 'Bugs and Limitations' section --- README.md | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index cb8b086..35de70b 100644 --- a/README.md +++ b/README.md @@ -497,29 +497,22 @@ them. ## Bugs and Limitations -* The number of elements `n` of the input `data` array is of type `uint16_t`, - which is exactly 2 bytes on all platforms. - * This means that the maximum number of elements is 65535. This should be - large enough for almost all applications on Arduino platforms, because - often the RAM size is limited. +* The number of elements `n` of the input `data` array is of type `uint16_t`. + * The maximum size of the input array is 65535. + * If you need bigger, copy the sorting algorithm that you want and change + the `uint16_t n` to a `uint32_t n`. * Using a fixed `uint16_t` means that the edge case behavior of these algorithms are consistency across all platforms. * Certain implementation choices and optimizations can be made if we know that `n` cannot exceed a bounded value. For example, the `shellSortTokuda()` function can use a pre-generated sequence of gaps which is a reasonable size because it only needs to go up to 65535. - * The alternative was to use the `size_t` type whose size is dependent on - the platform. On 8-bit processors, `size_t` is 2 bytes; on 32-bit - processors `size_t` is 4 bytes; and on 64-bit processors, `size_t` is 8 - bytes. However, I did not want to worry about edge case behavior of some - of these algorithms for extremely large values of `n`. - * There is also a common assumption that the natural-sized `int` (and - `unsigned int`) type is faster on their respective platforms . My actual - benchmarking experience suggests that this is not always true. Sometimes - it is, and sometimes it isn't, and the difference between using a - `uint16_t` versus `uint32_t` on a 32-bit processor is probably not as - great as choosing a better sorting algorithm. -* No hybrid sorting algorithms (yet). + * The alternative was to use the `size_t` type whose size is different on + different platforms: 2 bytes on 8-bit processors, 4 bytes on 32-bit + processors, and 8 bytes on 64-bit processors. However, I did not want to + worry about edge case behavior of some of these algorithms for extremely + large values of `n`. +* No hybrid sorting algorithms. * Different sorting algorithms are more efficient at different ranges of `N`. So hybrid algorithms will use different sorting algorithms at different points in their iteration. An example is the From d895bb0d7dbe261b7768ad2def819df2965eadbc Mon Sep 17 00:00:00 2001 From: Brian Park Date: Fri, 6 Aug 2021 10:53:47 -0700 Subject: [PATCH 09/12] examples/HelloSort: add HelloSort subsection to README.md --- CHANGELOG.md | 2 + README.md | 95 ++++++++++++++++++++++++++++---- examples/HelloSort/HelloSort.ino | 67 ++++++++++++++++++++++ examples/HelloSort/Makefile | 7 +++ 4 files changed, 160 insertions(+), 11 deletions(-) create mode 100644 examples/HelloSort/HelloSort.ino create mode 100644 examples/HelloSort/Makefile diff --git a/CHANGELOG.md b/CHANGELOG.md index 5468f4d..7daa56e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ * Unreleased * Add Selection Sort, mostly for completeness. It's another `O(N^2)` sort but is slower than Insertion Sort, and is not a stable sort. + * Add [examples/HelloSort](examples/HelloSort). + * Add **tl;dr** section in README.md to summarize my recommendations. * v0.1 (2021-08-04) * Add `combSort133()` which uses a gap factor of 4/3, which eliminates integer division. Smaller and faster on 8-bit processors which don't have diff --git a/README.md b/README.md index 35de70b..a0612b0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,12 @@ # AceSorting Various sorting functions targeted for the Arduino environment, implemented -using C++11 templates. Supports the following algorithms: +using C++11 template functions. The library is intended to be +compatible with most Arduino platforms, but some tradeoffs lean in favor of +lower-end processors (e.g. AVR, lower-end STM32) as opposed to higher-end +processors with larger amounts of RAM (e.g. ESP32, higher-end STM32). + +Supports the following algorithms: * Bubble Sort * `bubbleSort()` (not recommended) @@ -24,6 +29,20 @@ using C++11 templates. Supports the following algorithms: * `quickSortMedian()`: pivot on median of low, mid, high * `quickSortMedianSwapped()`: pivot on median and swap low, mid, high +**tl;dr** + +* In most cases, use `shellSortKnuth()`, costing only 142 bytes on an AVR and + 80-112 bytes on 32-bit processors. It is faster than any `O(N^2)` algorithm + while consuming only 34-82 extra bytes of flash over `insertionSort()`. +* If `N > ~100`, and you need faster sorting, and you have sufficient memory for + recursive functions, use `quickSortMiddle()` on 8-bit AVR processors, and + `quickSortMedianSwapped()` on 32-bit processors. +* Use `insertionSort()` if you need a stable sort. +* Use `combSort133()` or `shellSortClassic()` to get the smallest sorting + function faster than `O(N^2)`. +* Don't use the C library `qsort()`. It is 2-3X slower than the `quickSortXxx()` + functions in this library, and but consumes 4-5X more in flash bytes. + **Version**: 0.1 (2021-08-04) **Status**: Simple versions are working and stable. Need to add overloaded @@ -60,6 +79,57 @@ versions which take a custom comparator. * [Feedback and Support](#FeedbackAndSupport) * [Authors](#Authors) + +## Hello Sort + +This is a simplified version of the [examples/HelloSort](examples/HelloSort) +demo: + +```C++ +#include +#include + +using ace_sorting::shellSortKnuth; + +const uint16_t ARRAY_SIZE = 50; +int array[ARRAY_SIZE]; + +void printArray(int* array, uint16_t arraySize) { + for (uint16_t i = 0; i < arraySize; i++) { + Serial.print(array[i]); + Serial.print(' '); + } + Serial.println(); +} + +void fillArray(int* array, uint16_t arraySize) { + for (uint16_t i = 0; i < arraySize; i++) { + array[i] = random(256); + } +} + +void setup() { + delay(1000); + Serial.begin(115200); + while (!Serial); // Leonardo/Micro + + // Attempt to get a random seed using the floating analog pin. + randomSeed(analogRead(A0)); + + fillArray(); + Serial.println("Unsorted:"); + printArray(array, arraySize); + + // The compiler automatically generates the correct version of + // shellSortKnuth() based on the type of `array`. + shellSortKnuth(array, arraySize); + Serial.println("Sorted:"); + printArray(array, arraySize); +} + +void loop() {} +``` + ## Installation @@ -107,13 +177,16 @@ Some of the examples may depend on: ### Examples -* [examples/MemoryBenchmark](examples/MemoryBenchmark) - * Determine flash and static RAM consumption of various algorithms. -* [examples/AutoBenchmark](examples/AutoBenchmark) - * Determine CPU runtime of various algorithms. -* [examples/WorstCaseBenchmark](examples/WorstCaseBenchmark) - * Determine CPU runtime of worst case input data (e.g. sorted, reverse - sorted). +* [examples/HelloSort](examples/HelloSort) + * A demo of one of the sorting functions. +* Benchmarks + * [examples/MemoryBenchmark](examples/MemoryBenchmark) + * Determine flash and static RAM consumption of various algorithms. + * [examples/AutoBenchmark](examples/AutoBenchmark) + * Determine CPU runtime of various algorithms. + * [examples/WorstCaseBenchmark](examples/WorstCaseBenchmark) + * Determine CPU runtime of worst case input data (e.g. sorted, reverse + sorted). ## Usage @@ -568,9 +641,9 @@ Here are some of the reasons that I created my own library: informed trade off decisions. * I did not want to deal with the complexity of the C++ STL library. It is just too painful in an embedded environment. -* Lastly, I wanted to code my own sorting routines to make sure that I had a - complete understanding of each algorithm. I had forgotten so much - since my undergraduate years. +* Lastly, I wanted to implement my own sorting routines to make sure that I had + a complete understanding of each algorithm. I had forgotten so much since my + undergraduate years. ## License diff --git a/examples/HelloSort/HelloSort.ino b/examples/HelloSort/HelloSort.ino new file mode 100644 index 0000000..da54e6e --- /dev/null +++ b/examples/HelloSort/HelloSort.ino @@ -0,0 +1,67 @@ +/* + * Quick demo of one of the sorting functions: create an array of integers with + * random numbers, and sort the array. Print out the unsorted and sorted arrays. + * Other sorting functions follow the same pattern. The compiler is able to + * infer the type of the data, so you don't normally need to specify the + * template type to the shellSortKnuth() function. + */ + +#include +#include + +using ace_sorting::shellSortKnuth; + +#if !defined(SERIAL_PORT_MONITOR) + #define SERIAL_PORT_MONITOR Serial +#endif + +const uint16_t ARRAY_SIZE = 50; +int array[ARRAY_SIZE]; + +void printArray(int* array, uint16_t arraySize) { + for (uint16_t i = 0; i < arraySize; i++) { + SERIAL_PORT_MONITOR.print(array[i]); + SERIAL_PORT_MONITOR.print(' '); + } + SERIAL_PORT_MONITOR.println(); +} + +void fillArray(int* array, uint16_t arraySize) { + for (uint16_t i = 0; i < arraySize; i++) { + array[i] = random(256); + } +} + +//----------------------------------------------------------------------------- + +void setup() { +#if ! defined(EPOXY_DUINO) + delay(1000); +#endif + + SERIAL_PORT_MONITOR.begin(115200); + while (!SERIAL_PORT_MONITOR); // Leonardo/Micro + + // Attempt to get a random seed using the floating analog pin. +#if defined(EPOXY_DUINO) + randomSeed(micros()); +#else + randomSeed(analogRead(A0)); +#endif + + fillArray(array, ARRAY_SIZE); + SERIAL_PORT_MONITOR.println("Unsorted:"); + printArray(array, ARRAY_SIZE); + + // The compiler automatically generates the correct version of + // shellSortKnuth() based on the type of `array`. + shellSortKnuth(array, ARRAY_SIZE); + SERIAL_PORT_MONITOR.println("Sorted:"); + printArray(array, ARRAY_SIZE); + +#if defined(EPOXY_DUINO) + exit(0); +#endif +} + +void loop() {} diff --git a/examples/HelloSort/Makefile b/examples/HelloSort/Makefile new file mode 100644 index 0000000..79db6d2 --- /dev/null +++ b/examples/HelloSort/Makefile @@ -0,0 +1,7 @@ +# See https://github.com/bxparks/EpoxyDuino for documentation about using +# EpoxyDuino to compile and run AUnit tests natively on Linux or MacOS. + +APP_NAME := HelloSort +ARDUINO_LIBS := AceSorting +MORE_CLEAN := more_clean +include ../../../EpoxyDuino/EpoxyDuino.mk From fb5d5b26b43fa1a38b713e2fbf5d4d6ef56cd32d Mon Sep 17 00:00:00 2001 From: Brian Park Date: Fri, 6 Aug 2021 11:09:34 -0700 Subject: [PATCH 10/12] README.md: Fix typo, add HelloSort to TOC --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a0612b0..03d6fd6 100644 --- a/README.md +++ b/README.md @@ -41,17 +41,18 @@ Supports the following algorithms: * Use `combSort133()` or `shellSortClassic()` to get the smallest sorting function faster than `O(N^2)`. * Don't use the C library `qsort()`. It is 2-3X slower than the `quickSortXxx()` - functions in this library, and but consumes 4-5X more in flash bytes. + functions in this library, and consumes 4-5X more in flash bytes. **Version**: 0.1 (2021-08-04) -**Status**: Simple versions are working and stable. Need to add overloaded -versions which take a custom comparator. +**Status**: Simple versions are working and stable. Versions accepting custom +comparators coming soon. **Changelog**: [CHANGELOG.md](CHANGELOG.md) ## Table of Contents +* [Hello Sort](#HelloSort) * [Installation](#Installation) * [Source Code](#SourceCode) * [Dependencies](#Dependencies) From 23cf3432ce0ce4fab6ba56187cd1b09f52bfe2b9 Mon Sep 17 00:00:00 2001 From: Brian Park Date: Fri, 6 Aug 2021 12:46:06 -0700 Subject: [PATCH 11/12] Bump version to 0.2 --- CHANGELOG.md | 1 + README.md | 2 +- docs/doxygen.cfg | 2 +- examples/AutoBenchmark/README.md | 2 +- examples/AutoBenchmark/generate_readme.py | 2 +- examples/MemoryBenchmark/README.md | 2 +- examples/MemoryBenchmark/generate_readme.py | 2 +- examples/WorstCaseBenchmark/README.md | 2 +- examples/WorstCaseBenchmark/generate_readme.py | 2 +- library.properties | 2 +- src/AceSorting.h | 4 ++-- 11 files changed, 12 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7daa56e..931601c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog * Unreleased +* v0.2 (2021-08-06) * Add Selection Sort, mostly for completeness. It's another `O(N^2)` sort but is slower than Insertion Sort, and is not a stable sort. * Add [examples/HelloSort](examples/HelloSort). diff --git a/README.md b/README.md index 03d6fd6..b42ab58 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Supports the following algorithms: * Don't use the C library `qsort()`. It is 2-3X slower than the `quickSortXxx()` functions in this library, and consumes 4-5X more in flash bytes. -**Version**: 0.1 (2021-08-04) +**Version**: 0.2 (2021-08-06) **Status**: Simple versions are working and stable. Versions accepting custom comparators coming soon. diff --git a/docs/doxygen.cfg b/docs/doxygen.cfg index e7c0744..fa4b787 100644 --- a/docs/doxygen.cfg +++ b/docs/doxygen.cfg @@ -38,7 +38,7 @@ PROJECT_NAME = "AceSorting" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 0.1.0 +PROJECT_NUMBER = 0.2 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/examples/AutoBenchmark/README.md b/examples/AutoBenchmark/README.md index 5d404e1..dfc2896 100644 --- a/examples/AutoBenchmark/README.md +++ b/examples/AutoBenchmark/README.md @@ -2,7 +2,7 @@ Determine the speed of various AceSorting functions, for various array sizes. -**Version**: AceSorting v0.1 +**Version**: AceSorting v0.2 **DO NOT EDIT**: This file was auto-generated using `make README.md`. diff --git a/examples/AutoBenchmark/generate_readme.py b/examples/AutoBenchmark/generate_readme.py index 0f4f808..7967a22 100755 --- a/examples/AutoBenchmark/generate_readme.py +++ b/examples/AutoBenchmark/generate_readme.py @@ -27,7 +27,7 @@ Determine the speed of various AceSorting functions, for various array sizes. -**Version**: AceSorting v0.1 +**Version**: AceSorting v0.2 **DO NOT EDIT**: This file was auto-generated using `make README.md`. diff --git a/examples/MemoryBenchmark/README.md b/examples/MemoryBenchmark/README.md index 7b88d11..5a24b63 100644 --- a/examples/MemoryBenchmark/README.md +++ b/examples/MemoryBenchmark/README.md @@ -5,7 +5,7 @@ memory and static RAM sizes were recorded. The `FEATURE_BASELINE` selection is the baseline, and its memory usage numbers are subtracted from the subsequent `FEATURE_*` memory usage. -**Version**: AceSorting v0.1.0 +**Version**: AceSorting v0.2 **DO NOT EDIT**: This file was auto-generated using `make README.md`. diff --git a/examples/MemoryBenchmark/generate_readme.py b/examples/MemoryBenchmark/generate_readme.py index 7049952..59ee7a1 100755 --- a/examples/MemoryBenchmark/generate_readme.py +++ b/examples/MemoryBenchmark/generate_readme.py @@ -29,7 +29,7 @@ the baseline, and its memory usage numbers are subtracted from the subsequent `FEATURE_*` memory usage. -**Version**: AceSorting v0.1.0 +**Version**: AceSorting v0.2 **DO NOT EDIT**: This file was auto-generated using `make README.md`. diff --git a/examples/WorstCaseBenchmark/README.md b/examples/WorstCaseBenchmark/README.md index 7a32f72..e5a1461 100644 --- a/examples/WorstCaseBenchmark/README.md +++ b/examples/WorstCaseBenchmark/README.md @@ -7,7 +7,7 @@ could trigger worst case runtime. Three types of arrays are tested: * already sorted array * reverse sorted array -**Version**: AceSorting v0.1 +**Version**: AceSorting v0.2 **DO NOT EDIT**: This file was auto-generated using `make README.md`. diff --git a/examples/WorstCaseBenchmark/generate_readme.py b/examples/WorstCaseBenchmark/generate_readme.py index ab6876d..6f99678 100755 --- a/examples/WorstCaseBenchmark/generate_readme.py +++ b/examples/WorstCaseBenchmark/generate_readme.py @@ -32,7 +32,7 @@ * already sorted array * reverse sorted array -**Version**: AceSorting v0.1 +**Version**: AceSorting v0.2 **DO NOT EDIT**: This file was auto-generated using `make README.md`. diff --git a/library.properties b/library.properties index 874d71d..9d185a2 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=AceSorting -version=0.1.0 +version=0.2.0 author=Brian T. Park maintainer=Brian T. Park sentence=Various sorting algorithms for Arduino. diff --git a/src/AceSorting.h b/src/AceSorting.h index f5c6445..522fd1a 100644 --- a/src/AceSorting.h +++ b/src/AceSorting.h @@ -43,8 +43,8 @@ SOFTWARE. #endif // Version format: xxyyzz == "xx.yy.zz" -#define ACE_SORTING_VERSION 100 -#define ACE_SORTING_VERSION_STRING "0.1.0" +#define ACE_SORTING_VERSION 200 +#define ACE_SORTING_VERSION_STRING "0.2.0" #include "ace_sorting/swap.h" #include "ace_sorting/bubbleSort.h" From 523f6ae1ed95aa0be0ef56f82e0b4cae4f00c4a6 Mon Sep 17 00:00:00 2001 From: Brian Park Date: Fri, 6 Aug 2021 12:46:27 -0700 Subject: [PATCH 12/12] docs: Regenerate doxygen for v0.2 --- docs/html/AceSorting_8h_source.html | 18 +- docs/html/bubbleSort_8h.html | 2 +- docs/html/bubbleSort_8h_source.html | 2 +- docs/html/combSort_8h.html | 2 +- docs/html/combSort_8h_source.html | 2 +- docs/html/dir_000000_000001.html | 4 +- .../dir_54c88fbaa58defb9f1b2842cb9ef0a89.html | 4 +- .../dir_68267d1309a1af8e8297ef4c3efbcdba.html | 4 +- ...r_68267d1309a1af8e8297ef4c3efbcdba_dep.map | 2 +- ...r_68267d1309a1af8e8297ef4c3efbcdba_dep.md5 | 2 +- ...r_68267d1309a1af8e8297ef4c3efbcdba_dep.png | Bin 3014 -> 2914 bytes docs/html/files.html | 9 +- docs/html/graph_legend.html | 2 +- docs/html/index.html | 2 +- docs/html/insertionSort_8h.html | 2 +- docs/html/insertionSort_8h_source.html | 2 +- docs/html/quickSort_8h.html | 2 +- docs/html/quickSort_8h_source.html | 2 +- docs/html/search/all_5.js | 14 +- docs/html/search/files_0.js | 2 +- docs/html/search/files_1.js | 2 +- docs/html/search/files_2.js | 2 +- docs/html/search/files_3.js | 2 +- docs/html/search/files_4.js | 5 +- docs/html/search/functions_0.js | 2 +- docs/html/search/functions_1.js | 8 +- docs/html/search/functions_2.js | 2 +- docs/html/search/functions_3.js | 6 +- docs/html/search/functions_4.js | 9 +- docs/html/search/pages_0.js | 2 +- docs/html/selectionSort_8h.html | 159 ++++++++++++++++++ docs/html/selectionSort_8h__dep__incl.map | 4 + docs/html/selectionSort_8h__dep__incl.md5 | 1 + docs/html/selectionSort_8h__dep__incl.png | Bin 0 -> 6016 bytes docs/html/selectionSort_8h__incl.map | 4 + docs/html/selectionSort_8h__incl.md5 | 1 + docs/html/selectionSort_8h__incl.png | Bin 0 -> 5052 bytes docs/html/selectionSort_8h_source.html | 150 +++++++++++++++++ docs/html/shellSort_8h.html | 2 +- docs/html/shellSort_8h_source.html | 4 +- docs/html/swap_8h.html | 9 +- docs/html/swap_8h__dep__incl.map | 7 +- docs/html/swap_8h__dep__incl.md5 | 2 +- docs/html/swap_8h__dep__incl.png | Bin 37733 -> 41777 bytes docs/html/swap_8h_source.html | 2 +- 45 files changed, 397 insertions(+), 67 deletions(-) create mode 100644 docs/html/selectionSort_8h.html create mode 100644 docs/html/selectionSort_8h__dep__incl.map create mode 100644 docs/html/selectionSort_8h__dep__incl.md5 create mode 100644 docs/html/selectionSort_8h__dep__incl.png create mode 100644 docs/html/selectionSort_8h__incl.map create mode 100644 docs/html/selectionSort_8h__incl.md5 create mode 100644 docs/html/selectionSort_8h__incl.png create mode 100644 docs/html/selectionSort_8h_source.html diff --git a/docs/html/AceSorting_8h_source.html b/docs/html/AceSorting_8h_source.html index 552e746..8f8b7f4 100644 --- a/docs/html/AceSorting_8h_source.html +++ b/docs/html/AceSorting_8h_source.html @@ -22,7 +22,7 @@
AceSorting -  0.1.0 +  0.2
Sorting algorithms for Arduino (Bubble Sort, Insertion Sort, Shell Sort, Comb Sort, Quick Sort)
@@ -105,18 +105,20 @@
43 #endif
44 
45 // Version format: xxyyzz == "xx.yy.zz"
-
46 #define ACE_SORTING_VERSION 100
-
47 #define ACE_SORTING_VERSION_STRING "0.1.0"
+
46 #define ACE_SORTING_VERSION 200
+
47 #define ACE_SORTING_VERSION_STRING "0.2.0"
48 
49 #include "ace_sorting/swap.h"
50 #include "ace_sorting/bubbleSort.h"
-
52 #include "ace_sorting/shellSort.h"
-
53 #include "ace_sorting/combSort.h"
-
54 #include "ace_sorting/quickSort.h"
-
55 
-
56 #endif
+ +
53 #include "ace_sorting/shellSort.h"
+
54 #include "ace_sorting/combSort.h"
+
55 #include "ace_sorting/quickSort.h"
+
56 
+
57 #endif
+ diff --git a/docs/html/bubbleSort_8h.html b/docs/html/bubbleSort_8h.html index 1480d87..c7db59b 100644 --- a/docs/html/bubbleSort_8h.html +++ b/docs/html/bubbleSort_8h.html @@ -22,7 +22,7 @@
AceSorting -  0.1.0 +  0.2
Sorting algorithms for Arduino (Bubble Sort, Insertion Sort, Shell Sort, Comb Sort, Quick Sort)
diff --git a/docs/html/bubbleSort_8h_source.html b/docs/html/bubbleSort_8h_source.html index 8d52d7a..7bb4d5f 100644 --- a/docs/html/bubbleSort_8h_source.html +++ b/docs/html/bubbleSort_8h_source.html @@ -22,7 +22,7 @@
AceSorting -  0.1.0 +  0.2
Sorting algorithms for Arduino (Bubble Sort, Insertion Sort, Shell Sort, Comb Sort, Quick Sort)
diff --git a/docs/html/combSort_8h.html b/docs/html/combSort_8h.html index c9093d1..ddde37a 100644 --- a/docs/html/combSort_8h.html +++ b/docs/html/combSort_8h.html @@ -22,7 +22,7 @@
AceSorting -  0.1.0 +  0.2
Sorting algorithms for Arduino (Bubble Sort, Insertion Sort, Shell Sort, Comb Sort, Quick Sort)
diff --git a/docs/html/combSort_8h_source.html b/docs/html/combSort_8h_source.html index 319c753..b3f9820 100644 --- a/docs/html/combSort_8h_source.html +++ b/docs/html/combSort_8h_source.html @@ -22,7 +22,7 @@
AceSorting -  0.1.0 +  0.2
Sorting algorithms for Arduino (Bubble Sort, Insertion Sort, Shell Sort, Comb Sort, Quick Sort)
diff --git a/docs/html/dir_000000_000001.html b/docs/html/dir_000000_000001.html index a7a6eda..c9f71da 100644 --- a/docs/html/dir_000000_000001.html +++ b/docs/html/dir_000000_000001.html @@ -22,7 +22,7 @@
AceSorting -  0.1.0 +  0.2
Sorting algorithms for Arduino (Bubble Sort, Insertion Sort, Shell Sort, Comb Sort, Quick Sort)
@@ -67,7 +67,7 @@
-

src → ace_sorting Relation

File in srcIncludes file in src/ace_sorting
AceSorting.hbubbleSort.h
AceSorting.hcombSort.h
AceSorting.hinsertionSort.h
AceSorting.hquickSort.h
AceSorting.hshellSort.h
AceSorting.hswap.h
+

src → ace_sorting Relation

File in srcIncludes file in src/ace_sorting
AceSorting.hbubbleSort.h
AceSorting.hcombSort.h
AceSorting.hinsertionSort.h
AceSorting.hquickSort.h
AceSorting.hselectionSort.h
AceSorting.hshellSort.h
AceSorting.hswap.h