#!/usr/bin/perl -w use strict; use Benchmark qw( timethese ); use vars qw( %hash ); @hash{ 'A' .. 'Z', 'a' .. 'z' } = (1) x 52; timethese 100000, { 'defined' => sub { if (defined $hash{X}) { }; }, 'exists' => sub { if (exists $hash{X}) { }; }, 'as is' => sub { if ($hash{X}) { }; }, };
Benchmark: timing 100000 iterations of as is, defined, exists...
as is: 1 wallclock secs ( 0.16 usr + 0.00 sys = 0.16 CPU)
(warning: too few iterations for a reliable count)
defined: 0 wallclock secs ( 0.16 usr + 0.00 sys = 0.16 CPU)
(warning: too few iterations for a reliable count)
exists: 0 wallclock secs ( 0.16 usr + 0.00 sys = 0.16 CPU)
(warning: too few iterations for a reliable count)
In reply to Re^2: Hashing it out: defined? exists?
by eff_i_g
in thread Hashing it out: defined? exists?
by eff_i_g
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |