Thread exists() legt Hashkeys an (14 answers)
Opened by bloonix at 2007-02-22 20:24

bloonix
 2007-02-24 13:44
#74523 #74523
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
Just for fun :)

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use Benchmark;

my @keys = qw(a b c d e f g h i j);

sub _exists {
my %keys;
exists $keys{$_}{1}
for @keys;
}

sub _keyref {
my %keys;
$keys{$_} = {}
for @keys;
}

Benchmark::cmpthese(-1, {
'exists' => \&_exists,
'key=ref' => \&_keyref,
});


          Rate key=ref  exists
key=ref 80388/s      --    -10%
exists  89321/s     11%      --

          Rate key=ref  exists
key=ref 80388/s      --    -10%
exists  89647/s     12%      --

          Rate key=ref  exists
key=ref 79644/s      --    -11%
exists  89647/s     13%      --
\n\n

<!--EDIT|opi|1172317868-->
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.

View full thread exists() legt Hashkeys an