L
L
LittleFatNinja2015-05-15 00:19:49
PHP
LittleFatNinja, 2015-05-15 00:19:49

PHP bench mark. Concatenation vs array collection + implode. What's faster?

on different computers different results
who can say which is faster?
or who is not too lazy, test, tell me how you are
time php <file> > /dev/null

<?php
$out = '';

for ( $i = 0; $i < 1000000; $i++ ) {
    $out .= $i . '_' . $i;
}

echo $out;

?>

<?php
$out = [];

for ( $i = 0; $i < 1000000; $i++ ) {
    $out[] = sprintf('%s_%s', $i, $i);
}

echo implode('', $out);

?>

my ratio is
1) real: 0.4s
2) real: 1.4s

Answer the question

In order to leave comments, you need to log in

1 answer(s)
6
65536, 2015-05-15
@65536

0.458655834198
1.3961231708527

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question