Skip to content

Instantly share code, notes, and snippets.

@jose-neta
Forked from mjsr/benchmark_hash_by_ref.pl
Last active August 29, 2015 14:19
Show Gist options
  • Save jose-neta/0c85ab22d28f4a364bc1 to your computer and use it in GitHub Desktop.
Save jose-neta/0c85ab22d28f4a364bc1 to your computer and use it in GitHub Desktop.
#!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