Home > Backend Development > PHP Tutorial > instantiationexception php include efficiency comparison of two ways to load files

instantiationexception php include efficiency comparison of two ways to load files

WBOY
Release: 2016-07-29 08:43:36
Original
1176 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 the 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, and include this directly on the current page include files.
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.018272 161483765
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.0258450508 11768
0.024954080581665
0.024757146835327
0.02684497833252
Also, I tried loading all files directly on the current page
0.022285938262939
0.02439403 5339355
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? I don’t know. I hope I can give you a clear answer. Let’s ignore the core loading part of “Plan X” and just use the first method~

The above introduces the efficiency comparison between the two ways of loading files using instantiationexception php include, including the content of instantiationexception. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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