RE: Natural Sort - More speed Please
- Posted by Andy Serpa <renegade at earthling.net> Jun 04, 2002
- 461 views
Matthew Lewis wrote: > > > -----Original Message----- > > From: Tony Steward [mailto:tony at locksdownunder.com] > > > How ever it is too slow. Would anyone like to try to optimize this > > routine for greater speed. (As I have no idea how) > Yeah, it is kind of a lazy implementation, and it is certainly slow. (About 30x then normal sorting) It does the same breaking down of the strings over & over for each individual comparision in the sort. I only use it for very small lists so it usually doesn't matter. Just now I was playing around with this, and was able to cut the time in half by doing some preprocessing first, and then sorting. This assumes that all the elements are strings, which the original version doesn't. (If you only pass strings, you can probably speed it up a bit by taking out the string type-checking stuff.) I'll think about it a while and see if I come up with anything better... > Actually, you should use nat_compare() rather than nat_sort(). You > don't > need to sort the items, just do the comparison, since that's all windows > asks for (nat_sort() calls custom_sort() using nat_compare() for > comparisons): > I rarely use the API stuff, so I can't comment on that. But leaving the sorting to Windows sounds good too.