Bug #72745 [NEW]: reset() work much slower than foreach()
| From: | sailormax at inbox dot lv | Date: | Wed, 03 Aug 2016 15:22:43 +0000 |
| Subject: | Bug #72745 [NEW]: reset() work much slower than foreach() | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-202881@lists.php.net to get a copy of this message | ||
From: sailormax at inbox dot lv
Operating system:
PHP version: 7.0.9
Package: Arrays related
Bug Type: Bug
Bug description:reset() work much slower than foreach()
Description:
------------
reset() work much slower than foreach() under PHP7
Looks like developers optimized foreach(), but forgot about reset().
Under PHP5 speeds are similar.
Test script:
---------------
$arr = array_fill(0, 10000, "a");
$ts = microtime(true);
$first_key = -1;
foreach ($arr as $k => $v)
{
$arr2 = $arr;
reset($arr2);
$first_key = key($arr2);
}
echo microtime(true)-$ts, "<br />\n";
echo $first_key, "<br />\n";
$ts = microtime(true);
$first_key = -1;
foreach ($arr as $k => $v)
{
$arr2 = $arr;
foreach ($arr2 as $k2 => $v2) break;
$first_key = $k2;
}
echo microtime(true)-$ts, "<br />\n";
echo $first_key, "<br />\n";
Expected result:
----------------
0.0011060237884521
0
0.0011060237884521
0
Actual result:
--------------
0.64054489135742
0
0.0011060237884521
0
--
Edit bug report at https://bugs.php.net/bug.php?id=72745&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72745&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72745&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72745&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=72745&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=72745&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=72745&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=72745&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=72745&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=72745&r=support
Expected behavior: https://bugs.php.net/fix.php?id=72745&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=72745&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=72745&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=72745&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72745&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=72745&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=72745&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=72745&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72745&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=72745&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=72745&r=mysqlcfg