in reply to Re: Hashing it out: defined? exists?
in thread Hashing it out: defined? exists?
#!/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)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Hashing it out: defined? exists?
by ikegami (Patriarch) on Sep 02, 2005 at 20:15 UTC | |
by eff_i_g (Curate) on Sep 02, 2005 at 20:27 UTC | |
|
Re^3: Hashing it out: defined? exists?
by eff_i_g (Curate) on Sep 02, 2005 at 20:10 UTC |