1. RE: Natural Sort - More speed Please
- Posted by Matthew Lewis <matthewwalkerlewis at YAHOO.COM> Jun 04, 2002
- 396 views
> -----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) 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): global function LVnat_sort(integer id, integer item1, integer item2, integer column) return nat_compare( getLVItemText(id, item1, column), getLVItemText(id, item2, column)) end function The calls to getLVItemText() could be slowing you down, too. This was the reason that I originally coded win32lib to store the text of a listview (IIRC). It becomes a simple peek to get the item text, rather than asking windows for a pointer and then peeking the string. Matt Lewis
2. RE: Natural Sort - More speed Please
- Posted by Andy Serpa <renegade at earthling.net> Jun 04, 2002
- 389 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.
3. RE: Natural Sort - More speed Please
- Posted by Andy Serpa <renegade at earthling.net> Jun 04, 2002
- 392 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) > > Actually, you should use nat_compare() rather than nat_sort(). I guess I wasn't looking at the original code carefully. Although Matt is right by saying you should use nat_compare() instead of nat_sort() with only two items, SINCE you are only comparing two items the speed difference isn't going to be great. The only way I can think to speed up the SORTING is by removing the redundancies in the process so it doesn't have to keep breaking the same strings down by digits with each comparision. But with only two items that won't matter at all. I believe originally I tried converting the numbers to actual numbers instead of strings, but that was even slower that the add leading "0"'s system I ended up using. There is a C implementation somewhere -- I will take a look at it and see how they do it. Maybe it will apply to Euphoria...