leechael.orgHome

echo(), postscript

在上一篇 echo() 发布后, fcicq 就来添乱子了。 :D

$s = microtime(true);
echo str_repeat('Must I write something here? I don\'t know. But I need some characters for testing.<br />', 100000);
$e=microtime(true);
echo '<br /><br /> . ($e-$s);

0.0314919948578

$foo = array_fill(0, 100000, 'Must I write something here? I don\'t know. But I need some characters for testing.<br />');
$s = microtime(true);
$bar = implode('', $foo);
echo $bar;
$e=microtime(true);
echo '<br /><br /> . ($e-$s);

0.371160984039

用 str_repeat() 来循环同一个句子, 以及 implode() 来合并数组。首先说的是,str_repeat() 的表现很好,但却不是想要的: 没有人会在页面中呈现同一个句子,除非是 spammer。而implode() 的成绩与 for loop 相近。