-
-
Save jose-neta/0c85ab22d28f4a364bc1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!perl | |
use warnings; | |
use strict; | |
use Benchmark qw( cmpthese ); | |
my $h0 = { | |
'h1' => { | |
'h2' => { | |
'h3' => { | |
'h4' => { | |
'key' => 0, | |
}, | |
}, | |
}, | |
}, | |
}; | |
cmpthese(100_000_000, { | |
'use_direct' => sub { sub_direct() }, | |
'use_ref' => sub { sub_ref() }, | |
}); | |
sub sub_direct { | |
$h0->{'h1'}{'h2'}{'h3'}{'h4'}{'key'} = 1; | |
} | |
sub sub_ref { | |
my $h1 = $h0->{'h1'}; | |
my $h2 = $h1->{'h2'}; | |
my $h3 = $h2->{'h3'}; | |
my $h4 = $h3->{'h4'}; | |
$h4->{'key'} = 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment