develooper Front page | perl.perl5.porters | Postings from October 2014

Re: [perl #122947] [EXPERIMENT] Lvalue references

Thread Previous | Thread Next
From:
Kent Fredric
Date:
October 16, 2014 08:00
Subject:
Re: [perl #122947] [EXPERIMENT] Lvalue references
Message ID:
CAATnKFBhMw5yjcWOo0f4QmpskdCVZXh9fwMi0WNT23P0yefqfQ@mail.gmail.com
On 15 October 2014 04:06, H.Merijn Brand <h.m.brand@xs4all.nl> wrote:

> cmpthese (-3, {
>     arg3 => sub { my $foo = "foo"; substr ($foo, 1, 0) = "x"; },
>     arg4 => sub { my $foo = "foo"; substr  $foo, 1, 0,   "x"; },
>     });
>

What will really bake your noodle, put them both in void context instead of
in the return at the end of a sub.

use Benchmark qw( :hireswallclock cmpthese );

cmpthese(
    -3,
    {
        arg3 => sub { my $foo = "foo"; substr( $foo, 1, 0 ) = "x";},
        arg4 => sub { my $foo = "foo"; substr $foo, 1, 0, "x";},

        arg3_void => sub { my $foo = "foo"; substr( $foo, 1, 0 ) = "x"; 1 },
        arg4_void => sub { my $foo = "foo"; substr $foo, 1, 0, "x"; 1 },
    }
);


               Rate      arg3 arg4_void      arg4 arg3_void
arg3      2278016/s        --      -61%      -65%      -66%
arg4_void 5845748/s      157%        --      -11%      -13%
arg4      6556081/s      188%       12%        --       -2%
arg3_void 6712231/s      195%       15%        2%        --


that lone '1' on the end makes a difference of 200% :D

-- 
Kent

*KENTNL* - https://metacpan.org/author/KENTNL

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About