note 81718 added to function.empty
| From: | DavidfromCodeXplorer at osu1 dot php dot net | Date: | Tue, 11 Mar 2008 04:29:05 +0000 |
| Subject: | note 81718 added to function.empty | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136921@lists.php.net to get a copy of this message | ||
Mad Hampster did his test wrong. empty is NOT faster than a simple boolean check. The ONLY reason
to use empty() is for code readability. It is the same as an IF/ELSE check. But if you are dealing
with intermediate or higher level coders this function has no other benefit.
So, don't bother using EMPTY in the real world.
I ran an array with 5000 simple true/false values through four checks (both types twice) in case of
any gain one type might have by going first. These are my results generated one one page request.
(PHP5)
0.015328 Time EMPTY
0.014281 Time IF/ELSE
0.015239 Time EMPTY
0.013404 Time IF/ELSE
The page was accessed a couple times to reduce caching effects.
----
Server IP: 208.69.120.35
Probable Submitter: 208.101.216.113
----
Manual Page -- http://www.php.net/manual/en/function.empty.php
Edit -- https://master.php.net/note/edit/81718
Del: integrated -- https://master.php.net/note/delete/81718/integrated
Del: useless -- https://master.php.net/note/delete/81718/useless
Del: bad code -- https://master.php.net/note/delete/81718/bad+code
Del: spam -- https://master.php.net/note/delete/81718/spam
Del: non-english -- https://master.php.net/note/delete/81718/non-english
Del: in docs -- https://master.php.net/note/delete/81718/in+docs
Del: other reasons-- https://master.php.net/note/delete/81718
Reject -- https://master.php.net/note/reject/81718
Search -- https://master.php.net/manage/user-notes.php