Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^8: Undefined vs empty string

by Tux (Monsignor)
on Jun 05, 2013 at 12:32 UTC ( #1037196=note: print w/ replies, xml ) Need Help??


in reply to Re^7: Undefined vs empty string
in thread Undefined vs empty string

How does my defined-or solution compare on your system?

Where did I omit the empty string in

foreach $a (undef, "", 0, 1, "x" x 60) {

?

update new bench from your example. (my dor outperforms the other two consistently)

$ cat test.pl use strict; use Benchmark qw[ cmpthese ]; our @tests = ( (undef) x 1000, ("") x 1000, (chr(0)) x 1000, (0) x 1000, (1) x 1000, ("fred") x 1000, ); cmpthese -1, { a => q[ !(defined && length() ) and 1 for @tests; ], b => q[ !defined || $_ eq "" and 1 for @tests; ], c => q[ ($_ // "") eq "" and 1 for @tests; ], }; $ repeat 5 perl test.pl Rate b a c b 1950/s -- -18% -33% a 2379/s 22% -- -18% c 2901/s 49% 22% -- Rate b a c b 1950/s -- -22% -33% a 2511/s 29% -- -13% c 2901/s 49% 16% -- Rate b a c b 1950/s -- -23% -32% a 2536/s 30% -- -12% c 2875/s 47% 13% -- Rate b a c b 1914/s -- -22% -32% a 2466/s 29% -- -12% c 2801/s 46% 14% -- Rate b a c b 1950/s -- -23% -32% a 2536/s 30% -- -12% c 2875/s 47% 13% --

Enjoy, Have FUN! H.Merijn


Comment on Re^8: Undefined vs empty string
Select or Download Code
Replies are listed 'Best First'.
Re^9: Undefined vs empty string
by BrowserUk (Pope) on Jun 05, 2013 at 13:06 UTC
    Where did I omit the empty string in

    Damn. My eyes are getting like an old CRT. They are taking longer and longer to warm up in the mornings :)


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1037196]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (15)
As of 2015-07-31 20:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (281 votes), past polls