Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^7: How can I do a numeric sort on a substring? [Benchmark: reworked and extended]

by kcott (Archbishop)
on Jun 28, 2021 at 08:21 UTC ( [id://11134378]=note: print w/replies, xml ) Need Help??


in reply to Re^6: How can I do a numeric sort on a substring? (context matters)
in thread How can I do a numeric sort on a substring?

I wrapped all of the routines in @{[...]} to provide the list context; that was what I'd used in the preamble tests.

I added an STss as I had indicated this morning. I decided that STmcs was going to be pretty much the same as STss, so I skipped that one. I did add an mcse which was mcs with map BLOCK replaced by map EXPR.

sub st_sort_substr { @{[ map $_->[0], sort { $a->[1] <=> $b->[1] } map [$_, substr $_, 2], @unordered ]}; } sub map_cat_substr_expr { @{[ map "a-$_", sort { $a <=> $b } map substr($_, 2), @unordered ]}; }

I saw ++swl's post. There wasn't any code there, so I guessed.

use Sort::Key 'ikeysort'; use Sort::Key::Natural 'natsort'; ... sub sort_key_integer { @{[ ikeysort { substr $_, 2 } @unordered ]}; } sub sort_key_natural { @{[ natsort @unordered ]}; }

I ran the benchmark several times; there were no major differences between runs. Here's a sample output, in the spoiler; it's getting very wide (18 subroutines now) and this post is "Re^7", so probably best viewed via the "download" link.

And here's the code:

— Ken

Replies are listed 'Best First'.
Re^8: How can I do a numeric sort on a substring? [Benchmark: reworked and extended]
by swl (Parson) on Jun 28, 2021 at 09:49 UTC

    Not providing the code is a fairly egregious oversight on my part. Apologies for that.

    Your usage is the same as mine, but my code is in the spoiler for completeness.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11134378]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-25 06:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found