Re: Transform hash key?
- From: "DJ Stunks" <DJStunks@xxxxxxxxx>
- Date: 31 Jan 2006 10:27:10 -0800
A. Sinan Unur wrote:
>
> #!/usr/bin/perl
>
> use warnings;
> use strict;
>
> use Benchmark qw( cmpthese );
>
> my %h = map { $_ => 1 } ('aaa' .. 'zzz');
>
> cmpthese -1, {
> map => sub { %h = map { uc $_ => $h{$_} } keys %h },
> for => sub { $h{uc $_} = delete $h{$_} for keys %h; },
> };
>
> D:\Home\asu1\UseNet\clpmisc> s.pl
> Rate map for
> map 12.4/s -- -60%
> for 31.5/s 153% --
>
> So the for loop takes about 1/3 of the time the map takes, and
> this ratio remains roughly constant when the number of keys is
> increased.
>
> Nice.
Would it be possible to alias the keys and edit in-place? It would be
easy to do so with the values, but I'm not sure about the keys.
Just wondering.
Tks.
-jp
.
- Follow-Ups:
- Re: Transform hash key?
- From: Uri Guttman
- 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 doesn't sort properly?
- Previous by thread: Re: Transform hash key?
- Next by thread: Re: Transform hash key?
- Index(es):
Relevant Pages
|