04-29-2024, 07:37 PM
This really isn't a very efficient sort. ;(
For starters, your find the index on a linear search -- from start to finish. For 1000 items, that's 1000 comparisons to just *find* where to do the insert. At least swap that to a binary search method.
1000 items. Check 500. 250. 125. 62. 31. 15. 7. 3. 1. 0 <-- 10 checks MAX just found where to insert that new data, rather than 1000 max sequential checks.
Then inserting the data is a case of "shift every item right 1 element" from insert point to end of array. Again, not very efficient. Use _MEM, grab the whole block, move it all at once.
I've got a copy of this Binary Insertion Sort which uses mem either floating around here, or on the old forums somewhere. I'll see if I can dig it up for you later sometime, if you're interested in comparing its speed to yours.
For starters, your find the index on a linear search -- from start to finish. For 1000 items, that's 1000 comparisons to just *find* where to do the insert. At least swap that to a binary search method.
1000 items. Check 500. 250. 125. 62. 31. 15. 7. 3. 1. 0 <-- 10 checks MAX just found where to insert that new data, rather than 1000 max sequential checks.
Then inserting the data is a case of "shift every item right 1 element" from insert point to end of array. Again, not very efficient. Use _MEM, grab the whole block, move it all at once.
I've got a copy of this Binary Insertion Sort which uses mem either floating around here, or on the old forums somewhere. I'll see if I can dig it up for you later sometime, if you're interested in comparing its speed to yours.
