Comparison of the efficiency of two ways to load files with php include_PHP Tutorial

WBOY
Release: 2016-07-21 15:35:13
Original
1244 people have browsed it

Let’s talk about two methods first:
1) Define a string variable to store the list of files to be loaded. Then foreach loads.

Copy code The code is as follows:

$a = '/a.class.php;/Util/b .class.php;/Util/c.class.php';
$b = '/d.php;/e.class.php;/f.class.php;/g.class.php';
//Load basic system files
$kernel_require_files = explode(';', $a);//SYS_REQUIRE_LIB_FILE_LIST);
foreach($kernel_require_files as $f){
require_once(SYS_LIB_PATH.'/ System'.$f);
}

// Load basic system files
$kernel_require_files = explode(';', $b);//SYS_BASE_FILE_LIST);
foreach($ kernel_require_files as $f){
require_once(KERNEL_PATH.$f);
}

2) Load all the files to be loaded in an include file, The current page directly includes this include file.
include.php file content
Copy code The code is as follows:

require_once('func.php' );
require_once('LangManager.class.php');
require_once('_KernelAutoLoader.class.php');
require_once('ApplicationSettingManager.class.php');

require_once('lib/System/Activator.class.php');
require_once('lib/System/Util/CXML.class.php');
require_once('lib/System/Util/CWeb.class .php');

I personally think that the second method is more efficient because there are no redundant operations like foreach ~ everything must be demonstrated and cannot be imagined out of thin air, so I verified it. The following is the time it takes to load 10 times randomly using two methods:
foreach
0.017754077911377
0.017686128616333
0.017347097396851
0.018272161483765
0. 018272161483765
0.018401145935059
0.018187046051025
0.020787000656128
0.018001079559326
0.017963171005249


include_once('include.php');
0.025792121887207
0.024733066558838
0.025041103363037
0.024915933609009
0.024657011032104
0.024134159088135
0.025845050811768
0.024954080581665
0.024757146835327
0.02684497833252

Also, I tried it again and loaded all files directly on the current page
0.022285938262939
0.024394035339355
0.023194074630737
0.023229122161865
0.024644136428833
0.023538112640381
0.024240016937256
0.025094032287598
0. 023231029510498
0.02339506149292
The result surprised me! It turns out that the first method, which seems to be the slowest, takes the least time, and directly loading multiple files on the current page takes a lot of time~
The reason? Unknown, I hope you can give me a clear answer. Let’s ignore the core loading part of “Plan X” and just use the first method~

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/322301.htmlTechArticleLet’s talk about two methods first: 1) Define a string variable to store the list of files to be loaded. Then foreach loads. Copy the code The code is as follows: $a = '/a.class.php;/Util/b.cla...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!