"jr" <cre### [at] gmailcom> wrote:
> out of interest, what (timings) do you get when you use an already sorted array
> as inputs?
Very good question. Good thing you asked it too.
Bubble sorting 1000 items took 2.35 sec
Selection sorting 1000 items took 1.13 sec
Insertion sorting 1000 items took 1.57 sec
Quick sorting 1000 items took 88.01 ms
Shell sorting 1000 items took 112.01 ms
Heap sorting 1000 items took 208.01 ms
Bubble sorting 1000 items took 1.55 sec
Selection sorting 1000 items took 1.12 sec
Insertion sorting 1000 items took 9.00 ms
Quick sorting ***crashes with too many nested symbol tables***
Shell sorting 1000 items took 60.00 ms
Heap sorting 1000 items took 222.01 ms
So, there's still more work to be done to figure out how best to avoid this sort
I noticed while coding shell and heap that I needed to use floor () to fix some
divisions, and remove a "-1" to increase the upper bound of a loop to make sure
that everything got fully and properly sorted. So there's obviously a number
of issue under the hood that make coding in SDL much different than coding in
C++ or other languages.
These might be some low-level operations that ought to be investigated by
someone who codes in C or C++, to compare the outputs of simple divisions, etc.
Although there are more sorting algorithms that I'd like to get converted, I'll
post the current code here for archival purposes, and for folks too look at the
code and use the algorithms in their scene files. Caveat emptor.
Post a reply to this message
Download 'sorting.inc.txt' (12 KB)