in reply to Re^5: How can I do a numeric sort on a substring? (context matters)
in thread How can I do a numeric sort on a substring?
Out of curiosity I added some subs using Sort::Key. sort_key_natural is the natsort function from Sort::Key::Natural while sort_key_integer uses the ikeysort function from Sort::Key in tandem with substr.
The natsort approach is not particularly fast, but this is perhaps to be expected given it is a general purpose function (as are the unanchored regex approaches). I guess the integer key approach is faster as it takes advantage of direct string operations when building the keys, and then whatever optimisations Sort::Key uses internally.
I assume the differences in the order of the other approaches compared with Lanx's is due to the code being run on Strawberry perl 5.28. It would be interesting to know how the Sort::Key approaches go under a more recent Perl.
Edit: And now I look at the source code for Sort::Key::Natural, it is uses a regex approach to divide the string and pad out the numeric sections, so it is not surprising that it is slower than the other regex based approaches here. https://metacpan.org/dist/Sort-Key/source/lib/Sort/Key/Natural.pm#L34.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: How can I do a numeric sort on a substring? (context matters)
by salva (Canon) on Jun 28, 2021 at 09:15 UTC | |
by swl (Prior) on Jun 28, 2021 at 09:45 UTC | |
|
Re^7: How can I do a numeric sort on a substring? (context matters)
by kcott (Archbishop) on Jun 28, 2021 at 08:36 UTC |