对以下使用魔术方法和不适用魔术方法运行时间进行比较

使用魔术方法test1.php:

<?php 

/**
* 测试类
*/
class test
{
private $name = "jepeng"; public function __get($varname)
{
return $this->name;
}
} $i = 0; while ( $i<= 10000) {
$i++;
$test = new test();
$test->name;
}

不使用魔术方法test2.php

<?php 

/**
* 测试类
*/
class test
{
public $name = "jepeng";
} $i = 0; while ( $i<= 100000) {
$i++;
$test = new test();
$test->name;
}

检测

time php test1.php

time php test2.php

结果

test1.php
real 0m0.015s
user 0m0.008s
sys 0m0.006s test2.php
real 0m0.017s
user 0m0.014s
sys 0m0.002s

明显不使用魔术方法的运行时间是使用魔术方法的一半,如果项目很大,那么性能影响就会很大。

最新文章

  1. P1041 传染病控制
  2. Leetcode 198 House Robber
  3. About_AJAX
  4. idea集成git
  5. Tortoise SVN Clean up失败的解决方法
  6. HDU 5724 Chess (sg函数)
  7. (转载)常用JS加密编码算法 五:SHA1算法
  8. js模板引擎实现原理
  9. Android Studio无法关联Api23源码-提示Souces for android api 23 platform not found
  10. 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换算法(android)
  11. Mac 下 Chrome 快捷键大全
  12. SQL Sever数据库中 T-sql语句的使用(增、删、改、查)
  13. angularJS绑定数据中对标签转义的处理
  14. Golang 网络爬虫框架gocolly/colly 五 获取动态数据
  15. 关于warning: suggest parentheses around assignment used as truth value [-Wparentheses]|的解决方法
  16. 【Python】关于decode和encode
  17. hdu-1421(dp)
  18. centos7.5 修改网卡名称
  19. Windows 获取unix timestamp
  20. DB2安装过程中可能遇到的错误

热门文章

  1. RabbitMQ核心概念
  2. [CF995F]Cowmpany Cowmpensation
  3. 文档内容类似项处理-Shingling
  4. Java常用基础代码
  5. redis的maxmemory与maxmemory-policy关系
  6. hadoop之 hadoop 机架感知
  7. centos下安装docker最新版教程
  8. angular指令的详细讲解,不断补充
  9. ubuntu 16.04安装HUSTOJ过程
  10. netty基本组件介绍