Perl reference vs. handing over Benchmark

I want to know if there is a different between a shift and normal handing over to a sub in Perl.This is only for scalar, for big data(array,hash) there is of course a different.

use strict;
use Benchmark qw(:all) ;
my $a = 100;
my $x = 100;
print "".sub_ref(\$a,\$x)."\n";
print "".sub_normal($a,$x)."\n";

cmpthese(-1, {
'ref'     => sub {sub_ref(\$a,\$x)},
'normal'  => sub {sub_normal($a,$x)},

sub sub_ref {

sub sub_normal {

Our result:

            Rate    ref normal 
ref    2014189/s     --   -10% 
normal 2234181/s    11%     --

If its not necessary we should avoid references for scalar types, and try to iterate and not shift: Perl shift iterate Benchmark.But for Skalar values it is the fastest way to use prototypes.

4 thoughts on “Perl reference vs. handing over Benchmark”

  1. Thanks for sharing your info. I truly appreciate your efforts and I wwill be
    waiting for your further write ups thanks once again.

  2. I have been browsing online greater than three hours nowadays, but I by no means found any fascinating article like yours.
    It’s pretty price sufficient for me. In my
    view, if all webmasters and bloggers made just right content as you did, the net might be
    much more helpful than ever before.

  3. Howdy very cool web site!! Guy .. Excellent .. Amazing ..
    I will bookmark your website and take the feeds additionally?
    I am glad to seek out so many helpful info here in the put up,
    we want develop more strategies on this regard,
    thank you for sharing. . . . . .

  4. Excellent blog! Do you have any hints for
    aspiring writers? I’m planning to start my own website soon but I’m a little lost
    on everything. Would you propose starting with a free platform like WordPress or go for a paid option? There
    are so many options out there that I’m completely overwhelmed
    .. Any ideas? Thanks a lot!

Leave a Reply

Your email address will not be published.

4 × 1 =