I didn't realise C qsort() is so different across platforms ~ uses merge sort under glibc, smoothsort under musl etc. #picotron was using the number of compares to estimate virtual cpu cost, which is not meant to vary according to host! So for 0.3.0e, userdata:sort() uses a simple 3-partition, stable quicksort + single insertion sort pass (which turns out to be faster than qsort() because no cmp function call overhead).
@Felice It's just instead of doing many separate tiny sorts at the leaves of the quicksort (< ~20 elements). Also I put a maximum recursion depth for quicksort-unfriendly data and let the insertion sort pass take care of those leftovers too. Note, I don't have much evidence that this is a good approach, but the code is nice and small! (compared with quadsort etc, at least)
@zep Ahh yeah that makes sense. I think it's always been the done thing to switch it up at the final stage. Some people even use a handful of pre-written sort networks to handle cases ≤ N elements, which are the absolute fastest way to sort a list where you know the length N, but the code size rapidly balloons as N rises. So if you pick 5 as your minimum, you just have an array of functions where you call sort_net[N]() on any list at or below that.
@zep I don't know if it's due to a similar thing but I've also noticed that the "ls" command in pico-8 lists files in a different order depending on platform. I've tried it on pretty much every supported platform at this point (win, mac, linux and rpi) and the behaviour isn't consistent. although i'm not sure if it's affected by the file created/modified timestamp, which my syncing setup doesn't always preserve.
@zep 3-way quicksort ftw. Why the insertion sort pass tho?