#!/usr/bin/perl require 5.8.8; use strict; use fields; use Benchmark 'cmpthese'; use Hash::Util 'lock_keys'; use Data::Dumper; my @range = ('a'..'z'); # Define a perl 5.8 pseudo hash my $inputs = fields::phash(\@range, [ map { [1,1] } @range ]); $inputs->{c} = [ 0, 1 ]; $inputs->{f} = [ 2, 1 ]; $inputs->{g} = [ 0, 1 ]; my $phash = sub { map $inputs->{$_}, @range}; # Define an AofA with index conversion my @iRange = (0..25); my @array = map { [1, 1] } @iRange; my $aoa = sub { map $array[ ord($_)-97 ], @range }; # Define a hash my %HofA = map { $_=>[1, 1] } @range; my $hoa = sub { map $HofA{$_}, @range }; # Define a locked hash my %LHofA = map { $_=>[1, 1] } @range; lock_keys(%LHofA, @range); my $lhoa = sub { map $LHofA{$_}, @range }; cmpthese ( 10000, { pseudohash => $phash, Hash_of_Arrays => $hoa, Locked_Hash => $lhoa, Array_of_Arrays => $aoa, }); __END__ perl src/symarray.pl [8:54pm] (warning: too few iterations for a reliable count) (warning: too few iterations for a reliable count) Rate pseudohash Array_of_Arrays Hash_of_Arrays Locked_Hash pseudohash 19104/s -- -12% -36% -37% Array_of_Arrays 21695/s 14% -- -27% -29% Hash_of_Arrays 29767/s 56% 37% -- -2% Locked_Hash 30476/s 60% 40% 2% --