require和require_once经济性能对比
require和require_once都是PHP函数,开发人员可以使用它们在某个特定的脚本中导入外部PHP文件。你可以根据应用程序的复杂度调用一次或若干次require_once/require。使用require(而不是require_once)可以提高应用程序的性能。
测试前准备:
创建4个空的类来模拟主脚本要使用的外部PHP文件脚本。
ClassA.php:
<?php class ClassA
{ }
ClassB.php:
<?php class ClassB
{ }
ClassC.php:
<?php class ClassC
{ }
ClassD.php:
<?php class ClassD
{ }
使用require_once导入外部文件:
index.php:
<?php require_once './ClassA.php';
require_once './ClassB.php';
require_once './ClassC.php';
require_once './ClassD.php'; echo "Only testing require_once";
重启服务器,使用ab压力测试工具模拟10000个请求,同一时间有5个并发请求。
ab.exe -c 5 -n 10000 http://www.demo.com/optimization/index.php
测试结果:
D:\phpStudy\Apache\bin>ab.exe -c 5 -n 10000 http://www.demo.com/optimization/index.php
This is ApacheBench, Version 2.3 <$Revision: 1748469 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking www.demo.com (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests Server Software: Apache/2.4.23
Server Hostname: www.demo.com
Server Port: 80 Document Path: /optimization/index.php
Document Length: 25 bytes Concurrency Level: 5
Time taken for tests: 17.446 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 2280000 bytes
HTML transferred: 250000 bytes
Requests per second: 573.20 [#/sec] (mean)
Time per request: 8.723 [ms] (mean)
Time per request: 1.745 [ms] (mean, across all concurrent requests)
Transfer rate: 127.63 [Kbytes/sec] received Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.4 0 2
Processing: 2 8 90.4 4 2503
Waiting: 1 7 90.5 3 2503
Total: 2 8 90.4 4 2504 Percentage of the requests served within a certain time (ms)
50% 4
66% 5
75% 5
80% 5
90% 5
95% 5
98% 6
99% 6
100% 2504 (longest request)
使用ab工具测试require_once,可以看到相应时间是8.723ms,该脚本每秒支持573.20个请求。
使用require导入外部文件:
index_1.php:
<?php require './ClassA.php';
require './ClassB.php';
require './ClassC.php';
require './ClassD.php'; echo "Only testing require";
重启服务器,使用ab压力测试工具模拟10000个请求,同一时间有5个并发请求。
ab.exe -c 5 -n 10000 http://www.demo.com/optimization/index_1.php
测试结果:
D:\phpStudy\Apache\bin>ab.exe -c 5 -n 10000 http://www.demo.com/optimization/index_1.php
This is ApacheBench, Version 2.3 <$Revision: 1748469 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking www.demo.com (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests Server Software: Apache/2.4.23
Server Hostname: www.demo.com
Server Port: 80 Document Path: /optimization/index_1.php
Document Length: 20 bytes Concurrency Level: 5
Time taken for tests: 17.207 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 2230000 bytes
HTML transferred: 200000 bytes
Requests per second: 581.16 [#/sec] (mean)
Time per request: 8.604 [ms] (mean)
Time per request: 1.721 [ms] (mean, across all concurrent requests)
Transfer rate: 126.56 [Kbytes/sec] received Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.4 0 21
Processing: 1 8 86.5 4 2320
Waiting: 1 7 86.5 3 2320
Total: 1 8 86.5 4 2320 Percentage of the requests served within a certain time (ms)
50% 4
66% 5
75% 5
80% 5
90% 5
95% 6
98% 7
99% 7
100% 2320 (longest request) D:\phpStudy\Apache\bin>ab.exe -c 5 -n 10000 http://www.demo.com/optimization/index_1.php
This is ApacheBench, Version 2.3 <$Revision: 1748469 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking www.demo.com (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
使用ab工具测试require,可以看到相应时间是8.604ms,该脚本每秒支持581.16个请求。
require和require_once经济性能对比的更多相关文章
- 记录:sea.js和require.js配置 与 性能对比
最近有点忙,很久无写博客,记录一下之前的配置require.js和sea.js的配置.(有误有望提出 require.js 文件目录 /app(项目使用js) /lib(require.js jq存放 ...
- PHP函数include include_once require和require_once的区别
了解下include.include_once.require和require_once这4个函数: include函数:会将指定的文件读入并且执行里面的程序: require函数:会将目标文件的内容 ...
- [原] KVM 环境下MySQL性能对比
KVM 环境下MySQL性能对比 标签(空格分隔): Cloud2.0 [TOC] 测试目的 对比MySQL在物理机和KVM环境下性能情况 压测标准 压测遵循单一变量原则,所有的对比都是只改变一个变量 ...
- 浅谈C++之冒泡排序、希尔排序、快速排序、插入排序、堆排序、基数排序性能对比分析之后续补充说明(有图有真相)
如果你觉得我的有些话有点唐突,你不理解可以想看看前一篇<C++之冒泡排序.希尔排序.快速排序.插入排序.堆排序.基数排序性能对比分析>. 这几天闲着没事就写了一篇<C++之冒泡排序. ...
- Java--Stream,NIO ByteBuffer,NIO MappedByteBuffer性能对比
目前Java中最IO有多种文件读取的方法,本文章对比Stream,NIO ByteBuffer,NIO MappedByteBuffer的性能,让我们知道到底怎么能写出性能高的文件读取代码. pack ...
- C正则库做DNS域名验证时的性能对比
C正则库做DNS域名验证时的性能对比 本文对C的正则库regex和pcre在做域名验证的场景下做评测. 验证DNS域名的正则表达式为: "^[0-9a-zA-Z_-]+(\\.[0-9a ...
- [转]require(),include(),require_once()和include_once()区别
require(),include(),require_once()和include_once()区别 面试中最容易提到的一个PHP的问题,我想和大家共勉一下: require()和include() ...
- 开发语言性能对比,C++、Java、Python、LUA、TCC
一直想做开发语言性能对比,刚好有时间都做了给大家参考一下, 编译类:C++和Java表现还不错 脚本类:TCC脚本动态运行C语言,性能比其他脚本快好多... 想玩TCC的同学下载测试包,TCC目录下修 ...
- php+mysql预查询prepare 与普通查询的性能对比
prepare可以解决大访问量的网站给数据库服务器所带来的负载和开销,本文章通过实例向大家介绍预查询prepare与普通查询的性能对比,需要的朋友可以参考一下. 实例代码如下: <?php cl ...
随机推荐
- 第8步:安装Oracle
安装Oracle 注意,安装Oracle时需要以oracle用户身份执行,在那之前需要以root身份执行xhost+,即命令: 代码1 [root@sgdb1~]# xhost+ [root@sgdb ...
- ConfigurationSection类使用心得
ConfigurationSection类主要是方便我们用于扩展自定义webcongfig中的节点信息.我们可以方便的通过以下方式获取[自定义节点对象] [你自定义的对象] config = ([你自 ...
- ChemDraw 15.1 Pro插入阿尔法可以这样做
在理工科学科学习过程中,大家都会遇到各种希腊字母,而阿尔法(α)又是最常见的一个.最新版本ChemDraw 15.1 Pro的功能更加卓越,在很多功能上都进行了优化,操作更简便.其中,就可以很好的在公 ...
- IEnumerable 与 Iqueryable 的区别
IEnumerable 和 IQueryable 共有两组 LINQ 标准查询运算符,一组在类型为 IEnumerable<T> 的对象上运行,另一组在类型为 IQueryable&l ...
- 初识yeoman
最近开始新项目,在项目构建上面寻找合适的东西,grunt,bower到发现yeoman;学习了下,把一些东西记录下来然留着以后用. 1.什么是Yeoman Yeoman是Google的团队和外部贡献者 ...
- cocos2d-X学习之主要类介绍:场景(CCScene)
场景(CCScene) 类结构: CCScene主要有以下两个函数: bool init () //初始化函数 static CCScene * node (void) //生CCScene 作为 ...
- SAFEARRAY的使用(转载)
以下就是SAFEARRAY的Win32定义: typedef struct tagSAFEARRAY { unsigned short cDims; unsigned short fFeatures; ...
- Oracle Database Documentation
Oracle数据库的发展简史 ORDBMS对象-关系数据库管理系统 Oracle Schema Objects Oracle Schema Objects——Tables——Overview of T ...
- office 2010 自动连接网络打印机的问题(保存或者打开极慢) 解决方法
将默认打印机设为本地打印机或 Microsoft XPS Document Writer
- Python(数据库之数据类型)
一.创建表的完整语法 #[]内的可有可无,即创建表时字段名和类型是必须填写的,宽度与约束条件是可选择填写的. create table 表名( 字段名1 类型[(宽度) 约束条件], 字段名2 类型[ ...