Bug #67124 [NEW]: Typecast (bool) $array slowdown according to array length
| From: | vovan-ve at yandex dot ru | Date: | Thu, 24 Apr 2014 03:09:37 +0000 |
| Subject: | Bug #67124 [NEW]: Typecast (bool) $array slowdown according to array length | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-185403@lists.php.net to get a copy of this message | ||
From: vovan-ve at yandex dot ru
Operating system: Linux
PHP version: Irrelevant
Package: Performance problem
Bug Type: Bug
Bug description:Typecast (bool) $array slowdown according to array length
Description:
------------
Casting non-empty array to boolean using (bool) takes a time with
respect to array length. There are no reasons for this. This is
abnormal.
Any other checks like
if ($array), ($array) ?:, [] === $array
and
so on are not affected.
At least whole PHP 5 is affected by this issue.
Test script:
---------------
$tests = array(
'$empty' => array(),
'$full' => range(1, 1000),
);
$count = 1 * 1000 * 1000;
foreach ($tests as $name => $array) {
printf("%-10s", $name);
$start = microtime(true);
$i = $count;
while ($i-- > 0) {
(bool) $array;
}
$total = microtime(true) - $start;
printf("%6.2F sec. total\n", $total, $total / $count);
}
Actual result:
--------------
$empty 0.15 sec. total
$full 52.03 sec. total
--
Edit bug report at https://bugs.php.net/bug.php?id=67124&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=67124&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=67124&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=67124&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=67124&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=67124&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=67124&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=67124&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=67124&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=67124&r=support
Expected behavior: https://bugs.php.net/fix.php?id=67124&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=67124&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=67124&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=67124&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=67124&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=67124&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=67124&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=67124&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=67124&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=67124&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=67124&r=mysqlcfg