Js代码
- <?php
- function test( $f , $n=1 )
- {
- $t1 = microtime(true);
- for($i=0; $i<$n; ++$i)
- {
- $f();
- }
- $t2 = microtime(true);
- echo "<p>execute $f in ".($t2-$t1).' seconds</p>';
- }
- function f1()
- {
- $buf = array();
- for( $i=0; $i<100000; $i++)
- {
- $buf[] = 'good morning';
- }
- $s = join($buf);
- echo "<H1>".strlen($s)."</H1>";
- #echo "<div>$s</div>";
- }
- function f2()
- {
- $s = '';
- for($i=0;$i<100000;$i++)
- {
- $s .= 'good morning';
- }
- echo "<H1>".strlen($s)."</H1>";
- #echo "<div>$s</div>";
- }
- test('f1');
- test('f2');
- ?>
运行结果:
1200000
execute f1 in 1.2323458194733 ms
1200000
execute f2 in 0.64818692207336 ms
PHP中的 . 运算符很有效率 - -!
有点相关的文章
- PHP 截取字符串专题 (1.000)
- PHP 正则表达式 (0.584)
- php将HTML转换为txt文本的函数 (0.584)
- PHP 计算页面执行时间 (0.584)
- PHP中判断一个数组是否为空? (0.584)
- BioPerl安装指南:Unix/Linux/Windows下的安装 (RANDOM - 0.500)






