Skip to content

Instantly share code, notes, and snippets.

@luxifer
Created May 22, 2013 12:23
Show Gist options
  • Save luxifer/5627148 to your computer and use it in GitHub Desktop.
Save luxifer/5627148 to your computer and use it in GitHub Desktop.
bench concaténation
<?php
function benchStrintf() {
$begin = microtime(true);
for ($i=0; $i<1000000; $i++) {
$result = sprintf('%d = %d + %d selon %s', 42, 11, 31, 'php');
}
var_dump(microtime(true)-$begin);
}
function benchDot() {
$begin = microtime(true);
for ($i=0; $i<1000000; $i++) {
$result = 42 . ' = ' . 11 . ' + ' . 31 . ' selon php';
}
var_dump(microtime(true)-$begin);
}
function benchImplode() {
$begin = microtime(true);
for ($i=0; $i<1000000; $i++) {
$result = implode(" ", array(
42,
'=',
11,
31,
'selon',
'php'
));
}
var_dump(microtime(true)-$begin);
}
benchStrintf(); //double(0.9798150062561)
benchDot(); //double(0.67017388343811)
benchImplode(); //double(1.457218170166)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment