Created
November 14, 2012 11:17
-
-
Save chernomyrdin/4071598 to your computer and use it in GitHub Desktop.
test for non empty hash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w -- | |
use strict; | |
use Benchmark; | |
my %hash; | |
for (1..1e6) { | |
my $key = join($_, "*" x (10*rand), "*" x (10*rand)); | |
$hash{$key} = "*" x (100*rand); | |
} | |
timethese( 1e4, { | |
'scalar_keys' => sub { if (scalar(keys %hash)) { "OK" } }, | |
'scalar' => sub { if (scalar(%hash)) { "OK" } }, | |
'just_if' => sub { if (%hash) { "OK" } }, | |
} ); | |
__END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment