Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

G'day Dean,

"List::Util::pairmap would be an existing solution very similar to the new feature. It also seems to run quite quickly (but I can't compare it to for_list since I don't have a new-enough perl)."

No problem. I have v5.36.0 installed. I added your code to the OP benchmark code.

Mine starts as follows. Refer to "perl5360delta: use v5.36" for why I removed the strict and warnings pragmata.

#!/usr/bin/env perl use v5.36; use List::Util qw /pairs pairvalues pairmap/;

I then added:

  • say a_pairmap(); after the existing eight say statements.
  • a_pairmap     => \&a_pairmap, to the end of the cmpthese hashref.
  • Your sub a_pairmap { ... } verbatim, at the end of the script.

I ran the benchmark five times. All results were pretty much the same; here's a median set:

2500050000 2500050000 2500050000 2500050000 2500050000 2500050000 2500050000 2500050000 2500050000 Rate a_pairs_alias a_pairs h_each h_by_key h_for_list +h_vals a_pair_vals a_pairmap a_for_list a_pairs_alias 48.8/s -- -4% -67% -73% -83% + -90% -90% -92% -94% a_pairs 51.0/s 4% -- -66% -71% -82% + -90% -90% -91% -94% h_each 150/s 207% 193% -- -16% -47% + -69% -71% -74% -82% h_by_key 178/s 265% 249% 19% -- -37% + -64% -65% -69% -78% h_for_list 284/s 482% 457% 90% 59% -- + -42% -45% -51% -66% h_vals 490/s 903% 860% 227% 175% 72% + -- -5% -16% -41% a_pair_vals 513/s 951% 906% 243% 188% 81% + 5% -- -12% -38% a_pairmap 582/s 1091% 1041% 289% 226% 105% + 19% 13% -- -30% a_for_list 827/s 1594% 1521% 453% 364% 191% + 69% 61% 42% --

In all runs, a_pairmap was second fastest; and, h_by_key was faster than h_each (which differs from the OP results).

My environment:

$ perl -v | head -2 | tail -1 This is perl 5, version 36, subversion 0 (v5.36.0) built for cygwin-th +read-multi $ uname -a CYGWIN_NT-10.0 titan 3.2.0(0.340/5/3) 2021-03-29 08:42 x86_64 Cygwin

— Ken


In reply to Re^2: perl 5.36 and the for_list feature - a simple speed comparison by kcott
in thread perl 5.36 and the for_list feature - a simple speed comparison by swl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-04-19 10:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found