Re: String manipulation, optimize
- From: "Chung Leong" <chernyshevsky@xxxxxxxxxxx>
- Date: 9 Aug 2005 22:29:16 -0700
Ach, the meaningless debate that won't go away! The difference is so
miniscule that no one really knows which one is faster in a real-life
situations. Benchmark codes just give you bogus answers. The following
snippet, for instance, shows that the concatenation is more than an
order of magnitude slower than interpolation:
function getmicrotime() {
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$i = "hello";
$a = array_fill(0, 30000, "\$i");
$code1 = "\$s = " . implode(".", $a) . ";";
$code2 = "\$s = \"" . implode("", $a) . "\";";
$time_start = getmicrotime();
eval($code1);
$time_end = getmicrotime();
$time1 = $time_end - $time_start;
$time_start = getmicrotime();
eval($code2);
$time_end = getmicrotime();
$time2 = $time_end - $time_start;
echo "$time1 vs $time2";
The bottomline: it doesn't matter.
.
- Follow-Ups:
- Re: String manipulation, optimize
- From: R. Rajesh Jeba Anbiah
- Re: String manipulation, optimize
- References:
- String manipulation, optimize
- From: Rune
- String manipulation, optimize
- Prev by Date: Re: CVS for Databases?
- Next by Date: Re: <?= "Help" ?>
- Previous by thread: Re: minimal (?) optimization (Was Re: String manipulation, optimize)
- Next by thread: Re: String manipulation, optimize
- Index(es):