Re: Transform hash key?
- From: Uri Guttman <uri@xxxxxxxxxxxxxxx>
- Date: Tue, 31 Jan 2006 13:40:21 -0500
>>>>> "ASU" == A Sinan Unur <1usa@xxxxxxxxxxxxxxxxxxx> writes:
ASU> my %h = map { $_ => 1 } ('aaa' .. 'zzz');
ASU> cmpthese -1, {
ASU> map => sub { %h = map { uc $_ => $h{$_} } keys %h },
ASU> for => sub { $h{uc $_} = delete $h{$_} for keys %h; },
ASU> };
this benchmark has a common problem in that you don't set up the hash
the same way for each run. the first time you call either sub, the hash
will have only upper case keys. now i doubt that uc will be faster or
slower given any mix of input case but it still is wrong. if the
transform were something whose speed was data dependent, this benchmark
would be very bogus.
the map one could be fixed just by assigning it to a different hash. the
for one would need a fresh hash each time as it modifies it in place. so
you would need to do the same work for each one and my best idea would
be to copy the %h to %h2 inside each sub and use that as the input (and
you can use it for the output of the map. also choosing a different
output hash for the map could affect speed as well.
this is just a small lesson on the difficulty of properly benchmarking
apples and apples.
uri
--
Uri Guttman ------ uri@xxxxxxxxxxxxxxx -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
.
- Follow-Ups:
- Re: Transform hash key?
- From: A. Sinan Unur
- Re: Transform hash key?
- References:
- Transform hash key?
- From: MSG
- Re: Transform hash key?
- From: A. Sinan Unur
- Re: Transform hash key?
- From: Uri Guttman
- Re: Transform hash key?
- From: A. Sinan Unur
- Transform hash key?
- Prev by Date: Re: split the sequences
- Next by Date: Re: Why does Net::SFTP trigger my die handler when no errors?
- Previous by thread: Re: Transform hash key?
- Next by thread: Re: Transform hash key?
- Index(es):
Relevant Pages
|