note 126998 added to function.is-null
| From: | ahamilton9 at main dot php dot net | Date: | Tue, 19 Apr 2022 20:28:04 +0000 |
| Subject: | note 126998 added to function.is-null | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-218299@lists.php.net to get a copy of this message | ||
A quick test in 2022 on PHP 8.1 confirms there is still no need to micro-optimize NULL checks:
<?php
// Comparison Operator
$before = microtime(true);
$var = null;
for ($i=0 ; $i<1000000000 ; $i++) {
if($var === null) {}
}
$after = microtime(true);
echo ' ===: ' . ($after - $before) . " seconds\n";
// Function
$before = microtime(true);
$var = null;
for ($i=0 ; $i<1000000000 ; $i++) {
if(is_null($var)) {}
}
$after = microtime(true);
echo 'is_null: ' . ($after - $before) . " seconds\n";
// ===: 4.1487579345703 seconds
// is_null: 4.1316878795624 seconds
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.135 (proxied: 67.253.148.123)
----
Manual Page -- https://php.net/manual/en/function.is-null.php
Edit -- https://main.php.net/note/edit/126998
Del: integrated -- https://main.php.net/note/delete/126998/integrated
Del: useless -- https://main.php.net/note/delete/126998/useless
Del: bad code -- https://main.php.net/note/delete/126998/bad+code
Del: spam -- https://main.php.net/note/delete/126998/spam
Del: non-english -- https://main.php.net/note/delete/126998/non-english
Del: in docs -- https://main.php.net/note/delete/126998/in+docs
Del: other reasons-- https://main.php.net/note/delete/126998
Reject -- https://main.php.net/note/reject/126998
Search -- https://main.php.net/manage/user-notes.php