Re: require_once
| From: | mark@cyanox.nl | Date: | Tue, 24 Apr 2007 20:45:34 +0000 |
| Subject: | Re: require_once | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-29000@lists.php.net to get a copy of this message | ||
dletz@blog.de wrote:
Wow thats fast! On my machine i get these results: Win32 (PHP 5.2.1 CLI) require_once - 1.7735 sec myrequire_once - 1.0973 secI made two benchmarks one with relative paths and one with full paths. The full paths: <? $start_time = microtime(true); define('BASEPATH', dirname(__FILE__).'/'); function myrequire_once($file) { static $loaded = array(); if (!array_key_exists($file, $loaded)) {
$loaded[$file] = 1;
require $file;
}
}
for ($i=0;$i<1000;$i++) {
// require_once(BASEPATH.'manyClasses/'.$i.'.class.php');myrequire_once(BASEPATH.'manyClasses/'.$i.'.class.php'); } $execution_time = microtime(true) - $start_time; echo number_format($execution_time,4)."\n"; ?> Here the benchmarks with relative paths: Ubuntu 6.10, intel core 2 duo 1.66Ghz (It only uses one core afaik). PHP 5.2.0 (cli) (built: Mar 16 2007 19:40:08)
require_once 0.1123myrequire_once 0.2582 Ubuntu 6.10, Pentium 4 3Ghz (Dual core also but probably only using one core). PHP 5.1.6 (cli) (built: Mar 7 2007 12:48:25)
require_once 0.0984myrequire_once 0.2800 Ubuntu 7.04, AMD 64bit 3700+. PHP 5.2.1 (cli) (built: Feb 20 2007 20:11:58)
require_once 0.0663myrequire_once 0.1639 Windows 2000, AMD 64bit 3200+. PHP 5.1.4 (cli) (built: May 4 2006 10:35:22)
require_once 0.1590myrequire_once 0.5190 With full paths: Ubuntu 6.10, intel core 2 duo 1.66Ghz (It only uses one core afaik). PHP 5.2.0 (cli) (built: Mar 16 2007 19:40:08)
require_once 0.1032myrequire_once 0.3082 Ubuntu 6.10, Pentium 4 3Ghz (Dual core also but probably only using one core). PHP 5.1.6 (cli) (built: Mar 7 2007 12:48:25)
require_once 0.0967myrequire_once 0.2944 Ubuntu 7.04, AMD 64bit 3700+. PHP 5.2.1 (cli) (built: Feb 20 2007 20:11:58)
require_once 0.0634myrequire_once 0.1528 Windows 2000, AMD 64bit 3200+. PHP 5.1.4 (cli) (built: May 4 2006 10:35:22)
require_once 0.2115myrequire_once 0.6158 now I only have one windows system to test on but from this test it seems that the full path version is slower on windows then the relative paths. Which struck me as odd so I actually reran the tests several times. The myrequire_once function is generally slower across my test cases then require_once.