首页 | 源码下载 | 网站模板 | 网页特效 | 广告代码 | 网页素材 | 字体下载 | 书库 | 站长工具
会员投稿 投稿指南 RSS订阅
当前位置:主页>网络编程>PHP教程>资讯:再谈PHP单双引号问题

再谈PHP单双引号问题

www.jz123.cn  2012-10-09   来源:   站长家园    责任编辑(袁袁)    我要投递新闻

 

 

<?php
/*
* php 页面执行时间统计类
*
*/
class runtime
{
    var $StartTime = 0;
    var $StopTime = 0;
  
//获取微秒
function get_microtime()
    {
        list($usec, $sec) = explode(' ', microtime());
        return ((float)$usec + (float)$sec);
    }
//记录开始时间
    function start()
    {
        $this->StartTime = $this->get_microtime();
    }
//记录结束时间
    function stop()
    {
        $this->StopTime = $this->get_microtime();
    }
//计算所用时间&取整
    function spent()
    {
        return round(($this->StopTime - $this->StartTime) * 1000, 1);
    }
}
 
 
$runtime = new runtime();
 
 
//循环次数
$count = 10000;
$str = " string";
$str_single = 'This is a';
$str_double = "This is a";
$str_single_var = 'This is a'.$str;
$str_double_var = "This is a$str";
echo '<div style="display:none">';
 
//打印$count 次 单引号
 
$runtime->start();
for($i=0;$i<$count;$i++){
echo $str_single;
}
$runtime->stop();
$sp_single = $runtime->spent();
 
 
//打印$count 次 双引号
 
$runtime->start();
for($i=0;$i<$count;$i++){
echo $str_double;
}
$runtime->stop();
$sp_double = $runtime->spent();
 
 
//打印$count 次 单引号(混合)
 
$runtime->start();
for($i=0;$i<$count;$i++){
echo $str_single_var;
}
$runtime->stop();
$sp_single_var = $runtime->spent();
 
//打印$count 次 双引号(混合)
 
$runtime->start();
for($i=0;$i<$count;$i++){
echo $str_double_var;
}
$runtime->stop();
$sp_double_var = $runtime->spent();
 
echo '</div>';
 
echo '循环输出'.$count.'次,单引号用时:'.$sp_single.'  双引号用时: '.$sp_double.'  单引号(混合)用时:'.$sp_single_var.' 双引号(混合)用时:'.$sp_double_var;
 
 
?>

 

经测试发现,不混合的情况下,单引号的优势并不明显,混合时单引号效率明显优于双引号。

以后用以下格式: echo '<div style="display:none">';  即遵循w3c标准,又不会降低效率。  

 

改日用Opcodes试试

 


上一篇:phpmyadmin无法加载mcrypt的解决方法 下一篇:PHP好用文件上传类——单文件多文件上传

评论总数:0 [ 查看全部 ] 网友评论


关于我们隐私版权广告服务友情链接联系我们网站地图