以下の例で、PHP を短時間で実行するにはどうすればよいでしょうか? ケースAまたはB?これを適切にテストする方法は?
これにより、短時間で処理が高速になります。
ケース A:
/* -------------------------------------------------
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
------------------------------------------------- */
またはこれで?
ケース B:
/****************************************************
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
*****************************************************/
たとえば、テスト用にこのコードを使用しました。
<?php
echo '<pre>';
$s = microtime(true);
for ($i=0; $i<=10000000; $i++) {
/* -------------------------------------------------
------------------------------------------------- */
}
echo "1: ";
$r1 = microtime(true) - $s;
echo $r1;
echo "\n";
$s2 = microtime(true);
for ($i=0; $i<=10000000; $i++) {
/* -------------------------------------------------
some information inside commenting rules
------------------------------------------------- */
}
echo "2: ";
$r2 = microtime(true) - $s2;
echo $r2;
echo "\n";
$s3 = microtime(true);
for ($i=0; $i<=10000000; $i++) {
/* -------------------------------------------------
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
------------------------------------------------- */
}
echo "3: ";
$r3 = microtime(true) - $s3;
echo $r3;
echo "\n";
$s4 = microtime(true);
for ($i=0; $i<=10000000; $i++) {
/****************************************************
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
some information inside commenting rules
*****************************************************/
}
echo "4: ";
$r4 = microtime(true) - $s4;
echo $r4;
echo "\n";
$result = array('1 without text', $r1,
'2 single line', $r2,
'3 multiline separator', $r3,
'4 multiline starred', $r4);
echo min($result);
echo '</pre>';
結果は、実行とメモリ操作によって異なる場合があります。ほとんどの場合、私の場合の結果はCASE Bです。
あなたの結果はどうですか?