|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-04-01 00:16 UTC] php at edwardk dot info
Description:
------------
filemtime and other related functions are slower on php5 vs php4
Using PHP 5.2.1 and PHP 4.4.6 on Athlon X2 3800+, Windows 2003
the speed difference is about 50-100x slower.
Reproduce code:
---------------
<?
header('Content-type: text/plain');
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$time_start = microtime_float();
for ($i = 1; $i <= 1000; $i++) {
$blah = stat('.');
}
$time_end = microtime_float();
$time = $time_end - $time_start;
echo 'Took '.round(($time*100),3).'ms';
?>
Expected result:
----------------
Speeds should be similar
Actual result:
--------------
On PHP 4.4.6, it took about 1.6ms
On PHP 5.2.1 it took about 130ms
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 03:00:02 2025 UTC |
This is only the case when stat() fails. If you change stat('.'); to stat('<some file>'); you will se that PHP5 is faster than php4. Almost 2x.I have modified the code to use, $blah = stat('.htaccess'); This file does exist, it is 161 bytes on NTFS. PHP 4.4.6: 1.641ms PHP 5.1.2: 108.29ms Normally, I would be using the commands on many small files (400ish) in the current folder to determine if any of them had changed. This was fast enough on PHP4, but on PHP5, the same code takes much longer.Here's the new code: <? header('Content-type: text/plain'); function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } $time_start = microtime_float(); $c = 0; foreach (glob("*.torrent") as $filename) { $blah = stat($filename); $c++; } $time_end = microtime_float(); $time = $time_end - $time_start; echo 'Took '.round(($time*100),3).'ms for '.$c.' files'; ?> and the results: PHP 4.4.6 Took 5.232ms for 481 files PHP 5.2.1 Took 107.762ms for 481 files