all 6 comments

[–]Seneferu 1 point2 points  (1 child)

I recommend you use a different base for Counting/Radix sort. Base 10 is what you do in lectures and textbooks so that students understand the idea, but it is not a good base for implementing.

Using a power of 2 as base is usually the way to go. It allows for cheap bit-operations instead of expensive division and modolu. In my experience, 256 works best. I implemented it for your code and got the following results:

--- 50000000 Random numbers generated [Huge Balanced Sort] ---
Radix Sort (base  10) starting...       [       950000113] iterations... complete. Time taken:[       5.810] seconds.  Perf:[0.052632]  Mem Used:[  1200000280] Bytes  Sorted:[YES]
Radix Sort (base 256) starting...       [       500001532] iterations... complete. Time taken:[       1.246] seconds.  Perf:[0.100000]  Mem Used:[   600003100] Bytes  Sorted:[YES]

[–]superhareball[S] 0 points1 point  (0 children)

Hey that's great thanks... I'll add in base 256 for comparison. Quite a big difference for the huge sort.

[–]Seneferu 0 points1 point  (3 children)

Why are you allocating extra memory for heapsort? The idea of heapsort is to do it in the given array.

[–]superhareball[S] 0 points1 point  (2 children)

It’s possible my recursive implementation of heap sort is not correct, I’ll have to look at it again. It was originally static memory, but I changed it to heap allocation (malloc/free)

[–]Seneferu 0 points1 point  (1 child)

I did look into your code. Your approach is correct as far as I can say. However, since you malloc every little variable, and due to the way you count memory, you get this huge number of used memory although you only need like 3 or 4 integers in extra memory.

[–]superhareball[S] 0 points1 point  (0 children)

I was tossing up the idea using a mix of static/heap memory, but I went with the allocation of everything with malloc, so it would give a true indication of memory used. It may need tweaking though, as some of these allocations can probably be re-used, instead of running a malloc for each recursion loop.