PHP include loading files Two ways efficiency comparison _php skill

Source: Internet
Author: User
Let's say two ways:
1 defines a string variable that holds the list of files to be loaded. Then foreach loads.
Copy Code code 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 All the files to be loaded in an include file loaded, the current page directly include this include file.
include.php File Contents
Copy Code code 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 is no such redundant operation of foreach ~ All things to prove, not a figment of the imagination, so I verified. The following is the time that is consumed by randomly loading 10 times in two ways:
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

In addition, try again to load 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! Unexpectedly, the first seemingly slowest method, the least time-consuming, and directly on the current page to load more than a few files time-consuming ah ~
Reason? Unknown Ah, hope to give an answer to the eye, no matter how many "x plan" the core load part of the first method of the ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.