Skip to content

Instantly share code, notes, and snippets.

@chernomyrdin
Created November 14, 2012 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chernomyrdin/4071598 to your computer and use it in GitHub Desktop.
Save chernomyrdin/4071598 to your computer and use it in GitHub Desktop.
test for non empty hash
#!/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