#! perl -slw use strict; #use Math::Random::MT qw[ rand ]; use Devel::Size qw[ total_size ]; our $S //= 1; srand( $S ); my %hash; for( 1 .. 1e6 ) { my( $x, $y, $z ) = ( int( rand 20 ), int( rand 1.2e6 ), int( rand 1.2e6 ) ); # ++$hash{ $x }{ $y }{ $z }; # ++$hash{ join $;, $x, $y, $z }; # ++$hash{ pack 'Q', $x * 1.2e6**2 + $y * 1.2e6 + $z }; ++$hash{ unpack 'A6', pack 'Q', $x * 1.2e6**2 + $y * 1.2e6 + $z }; } print total_size( \%hash ), ' ', scalar keys %hash; __END__ ++$hash{ $x }{ $y }{ $z }; 269 897 378 ++$hash{ join $;, $x, $y, $z }; 106 036 953 40% ++$hash{ pack 'Q', $x * 1.2e6**2 + $y * 1.2e6 + $z }; 98 388 672 36.5% ++$hash{ unpack 'A6', pack 'Q', $x * 1.2e6**2 + $y * 1.2e6 + $z }; 96 193 539 35.6% #### C:\test>perl -E"say join ' ', int( rand 20 ), sort{ $a<=>$b } int( rand 1.2e6 ), int( rand 1.2e6 ) for 1 .. 1e6" | sort | perl -nle"if($last eq $_){ ++$n }else{ print qq[$last : $n];$n=1} $last=$_" | wc -l 999978