[Chicago-talk] appending hashes

Brian Katzung briank at kappacs.com
Tue Nov 4 22:46:58 CST 2003


Jay Strauss wrote:

> What's the baseline showing?  Just how long it takes to copy a hash?

Specifically, I wanted to simulate the original conditions inside the 
timing loop: appending a new hash to an existing hash, but from a 
consistent state each time (thus, initializing %a = %b).

Since what I really wanted was to compare the time for %a = (%a, %c) to 
@a{keys(%c)} = values(%c), I needed to subtract the time for %a = %b. 
The baseline time is that time.

   -- Brian

> Jay
> ----- Original Message ----- 
> From: "Brian Katzung" <briank at kappacs.com>
> To: "Chicago.pm chatter" <chicago-talk at mail.pm.org>
> Sent: Monday, November 03, 2003 10:06 PM
> Subject: Re: [Chicago-talk] appending hashes
> 
> 
> 
>>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