#!/usr/bin/perl use strict; use warnings; use Time::HiRes; use Benchmark qw(cmpthese :hireswallclock); my @bogus; $bogus[1]{foo}[2]{bar}[3]{baz} = 5; $bogus[1]{foo}[2]{bar}[3]{quux} = 6; our @bogus2; $bogus2[1]{foo}[2]{bar}[3]{baz} = 5; $bogus2[1]{foo}[2]{bar}[3]{quux} = 6; cmpthese(1_000_000, { without_common => sub { my $prod = $bogus[1]{foo}[2]{bar}[3]{baz} * $bogus[1]{foo}[2]{bar}[3]{quux}; }, with_common => sub { my $common = $bogus[1]{foo}[2]{bar}[3]; my $prod = $common->{baz} * $common->{quux}; }, without_common_g => sub { my $prod = $bogus2[1]{foo}[2]{bar}[3]{baz} * $bogus2[1]{foo}[2]{bar}[3]{quux}; }, with_common_g => sub { my $common = $bogus2[1]{foo}[2]{bar}[3]; my $prod = $common->{baz} * $common->{quux}; }, });