ホームページ  >  記事  >  php教程  >  PHP の一重引用符と二重引用符についてもう一度話しましょう

PHP の一重引用符と二重引用符についてもう一度話しましょう

WBOY
WBOYオリジナル
2016-06-21 08:51:121193ブラウズ

テーブル>

テストの結果、単一引用符を混合しない場合には、単一引用符の利点が明らかではないことがわかりました。混合すると、単一引用符の効率が二重引用符の効率よりも大幅に向上します。

将来的には、効率を低下させることなく w3c 標準に準拠する echo '

'; の形式を使用します。

別の日にオペコードを使用してみてください

選択した場合は、ソースの追加にご協力ください: http://www.3oom.com/blog/16.html



/*

* 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 '

';

 

//打印$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 '

';

 

echo '循环输出'.$count.'次,单引号用时:'.$sp_single.'  双引号用时: '.$sp_double.'  单引号(混合)用时:'.$sp_single_var.' 双引号(混合)用时:'.$sp_double_var;

 

 

?>

<🎜> /*<🎜> <🎜> * PHP ページ実行時間統計クラス<🎜> <🎜> *<🎜> <🎜> */<🎜> <🎜> クラスランタイム<🎜> <🎜> {<🎜> <🎜> var $StartTime = 0;<🎜> <🎜> var $StopTime = 0;<🎜> <🎜> <🎜> <🎜> //マイクロ秒を取得<🎜> <🎜> 関数 get_microtime()<🎜> <🎜> {<🎜> <🎜> List($usec, $sec) =explode(' ', microtime());<🎜> <🎜> return ((float)$usec + (float)$sec);<🎜> <🎜> }<🎜> <🎜> // 記録開始時刻<🎜> <🎜> 関数 start()<🎜> <🎜> {<🎜> <🎜> $this->StartTime = $this->get_microtime();<🎜> <🎜> }<🎜> <🎜> //終了時刻を記録<🎜> <🎜> 関数 stop()<🎜> <🎜> {<🎜> <🎜> $this->StopTime = $this->get_microtime();<🎜> <🎜> }<🎜> <🎜> //時間と丸めを計算します<🎜> <🎜> 関数の使用済み()<🎜> <🎜> {<🎜> <🎜> returnround(($this->StopTime - $this->StartTime) * 1000, 1);<🎜> <🎜> }<🎜> <🎜> }<🎜> <🎜> <🎜> <🎜> <🎜> <🎜> $runtime = 新しいランタイム();<🎜> <🎜> <🎜> <🎜> <🎜> <🎜> //ループ数<🎜> <🎜> $count = 10000;<🎜> <🎜> $str = " 文字列";<🎜> <🎜> $str_single = 'これは';<🎜> <🎜> $str_double = "これは";<🎜> <🎜> $str_single_var = 'これは'.$str;<🎜> <🎜> $str_double_var = "これは $str";<🎜> <🎜> echo '
'; //$count 倍の一重引用符を出力します $runtime->start(); for($i=0;$i echo $str_single; } $runtime->stop(); $sp_single = $runtime->spent(); // $count 倍二重引用符を出力します $runtime->start(); for($i=0;$i echo $str_double; } $runtime->stop(); $sp_double = $runtime->spent(); // $count 倍の一重引用符 (混合) を出力します $runtime->start(); for($i=0;$i echo $str_single_var; } $runtime->stop(); $sp_single_var = $runtime->spent(); //$count 倍の二重引用符 (混合) を出力します $runtime->start(); for($i=0;$i echo $str_double_var; } $runtime->stop(); $sp_double_var = $runtime->spent(); echo '
'; echo '.$count.' 回のループ出力、一重引用符の時間: '.$sp_double.' 一重引用符 (混合) の時間: '.$sp_single_var.'使用法: '.$sp_double_var; ?>
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。