[Chicago-talk] appending hashes

Brian Katzung briank at kappacs.com
Mon Nov 3 22:06:51 CST 2003


katzung at moon [1056] cat hashtest
use Benchmark;

%b = map(($_, $_), 'AA' .. 'ZZ');
%c = map(($_, $_), 0 .. 675);

timethese(1000,
{
         'baseline' => sub
         {
                 %a = %b;
         },
         'unroll' => sub
         {
                 %a = %b;
                 %a = (%a, %c);
         },
         'append' => sub
         {
                 %a = %b;
                 @a{keys(%c)} = values(%c);
         }
}
);
katzung at moon [1057] perl hashtest
Benchmark: timing 1000 iterations of append, baseline, unroll...
     append:  9 wallclock secs ( 8.56 usr +  0.00 sys =  8.56 CPU) @ 
116.82/s (n=1000)
   baseline:  5 wallclock secs ( 4.57 usr +  0.00 sys =  4.57 CPU) @ 
218.82/s (n=1000)
     unroll: 24 wallclock secs (22.42 usr +  0.00 sys = 22.42 CPU) @ 
44.60/s (n=1000)

YMMV

   - Brian





More information about the Chicago-talk mailing list