use strict; use warnings; use Benchmark qw(cmpthese); my %hash = ( 1 => 'one' , 2 => 'two' , 3 => 'three' ); cmpthese (-1, { 'orig' => sub {orig ()}, 'roy' => sub {roy ()}, 'GF' => sub {GF ()}, 'VS' => sub {VS ()}, 'davido' => sub {davido ()}, 'sneekyGF' => sub {sneekyGF ()}, 'sneekyDuff' => sub {sneekyDuff ()}, } ); sub orig { my (@one, @two); foreach ( keys %hash ) { push @one , $hash{$_}; push @two, $_; } } sub roy { my (@one, @two); push @one, values %hash; push @two, keys %hash; } sub GF { my (@one, @two); (push @one , $hash{$_}), push @two, $_ foreach ( keys %hash ); } sub VS { my (@one, @two); @one = values %hash; @two = keys %hash; } sub davido { my( @one ) = @hash{ my( @two ) = keys %hash }; } sub sneekyGF { my (@one, @two); --$| ? push @one, $_ : push @two, $_ foreach %hash; } sub sneekyDuff { my (@one, @two); push @{--$| ? \@one : \@two}, $_ for %hash; } sub BUK { my (@one, @two); 1 while ( $one[@one], $two[@two] ) = each %hash; } #### Rate sneekyDuff BUK sneekyGF orig GF roy VS davido sneekyDuff 55138/s -- -3% -20% -40% -40% -52% -54% -55% BUK 57031/s 3% -- -18% -38% -38% -51% -52% -53% sneekyGF 69161/s 25% 21% -- -25% -25% -40% -42% -43% orig 92056/s 67% 61% 33% -- -0% -21% -23% -25% GF 92056/s 67% 61% 33% 0% -- -21% -23% -25% roy 115883/s 110% 103% 68% 26% 26% -- -3% -5% VS 119184/s 116% 109% 72% 29% 29% 3% -- -2% davido 122008/s 121% 114% 76% 33% 33% 5% 2% --