#!/usr/bin/env perl use strict; use warnings; use Benchmark 'cmpthese'; my %big_hash = map { $_ => 1 } 1 .. 1_000; sub _get_original_hash { return %big_hash } sub _get_ref_to_hash { return \%big_hash } sub _get_anon_hashref { return { %big_hash } } cmpthese 0 => { orig => sub { my %hash = _get_original_hash() }, ref => sub { my $ref = _get_ref_to_hash() }, anon => sub { my $anon = _get_anon_hashref() }, }; #### Rate orig anon ref orig 4495/s -- -5% -100% anon 4756/s 6% -- -100% ref 5554928/s 123471% 116697% -- #### my %big_hash = map { $_ => 1 } 1 .. 1_000_000; #### anon 1.23/s -- -4% -100% orig 1.28/s 4% -- -100% ref 5557956/s 451583832% 434909964% -- #### my $mycorpus = getCorpus('C:\Users\li\test'); print "$_ : $mycorpus{$_}\n" for sort keys %$mycorpus; #### dd getCorpus('C:\Users\li\test');