in reply to Re^6: Undefined vs empty string
in thread Undefined vs empty string
I was actually kind of hoping that the example showed just that.
Here's an even mix of possible values including the empty string which you omitted, and the results are too close to call.:
#! perl -slw use strict; use Benchmark qw[ cmpthese ]; our @tests = ( (undef) x1000, ('') x1000, (chr(0)) x1000, (0) x1000, (1) x1000, ('fred') x1000, ); cmpthese -1, { a => q[ !(defined && length() ) and 1 for @tests; ], b => q[ !defined || $_ eq '' and 1 for @tests; ], }; __END__ C:\test>junk Rate b a b 1029/s -- -17% a 1239/s 20% -- C:\test>junk Rate b a b 1065/s -- -1% a 1079/s 1% --
Much of a muchness.
I guess you could get into varying the proportions of the mix commensurate with your application expectations, but ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: Undefined vs empty string
by Tux (Canon) on Jun 05, 2013 at 12:32 UTC | |
by BrowserUk (Patriarch) on Jun 05, 2013 at 13:06 UTC |