Your benchmarks support my point. But there are two subs missing - assignment of a passed hash reference to a scalar and to a hash:

use strict; use warnings; use Benchmark qw(cmpthese); for my $argCount (2, 10, 100) { my @args = (1 .. $argCount); print "\nFor $argCount elements:\n"; cmpthese (-1, { hashArg => sub { noCopy ({@args}) }, listArg => sub { noCopy ( @args) }, toList => sub { toList ( @args) }, toHash => sub { toHash ( @args) }, rtoHref => sub { rtoHref ({@args}) }, rtoHash => sub { rtoHash ({@args}) }, } ); } sub noCopy { } sub toList { my @args = @_ } sub toHash { my %hash = @_ } sub rtoHash { my %hash = %{$_[0]} } sub rtoHref { my ($hash) = @_ }

which yields

For 2 elements: Rate rtoHash rtoHref hashArg toList toHash listArg rtoHash 455110/s -- -35% -48% -49% -50% -82% rtoHref 695078/s 53% -- -21% -23% -24% -72% hashArg 877714/s 93% 26% -- -2% -4% -65% toList 899514/s 98% 29% 2% -- -2% -64% toHash 918729/s 102% 32% 5% 2% -- -63% listArg 2513115/s 452% 262% 186% 179% 174% -- For 10 elements: Rate rtoHash rtoHref toList toHash hashArg listArg rtoHash 166131/s -- -49% -51% -54% -54% -93% rtoHref 324588/s 95% -- -5% -10% -11% -86% toList 342024/s 106% 5% -- -5% -6% -85% toHash 360654/s 117% 11% 5% -- -1% -84% hashArg 364089/s 119% 12% 6% 1% -- -84% listArg 2271050/s 1267% 600% 564% 530% 524% -- For 100 elements: Rate rtoHash rtoHref hashArg toList toHash listArg rtoHash 18862/s -- -49% -54% -55% -55% -98% rtoHref 36885/s 96% -- -10% -13% -13% -96% hashArg 40959/s 117% 11% -- -3% -3% -96% toList 42164/s 124% 14% 3% -- -0% -96% toHash 42347/s 125% 15% 3% 0% -- -96% listArg 1037900/s 5403% 2714% 2434% 2362% 2351% --

which shows that constructing a hash reference from the argument list and actually using it is always slowest; passing a plain list is fastest.


In reply to Re^4: hash interface by shmem
in thread hash interface by baxy77bax

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.