Skip to content

Instantly share code, notes, and snippets.

@tarto-dev
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save tarto-dev/e1b9648b4c4ab9dc0859 to your computer and use it in GitHub Desktop.

Select an option

Save tarto-dev/e1b9648b4c4ab9dc0859 to your computer and use it in GitHub Desktop.

Output generated by typing "php bench >> output"

SPRINTF: 0.32848882675171

CONCAT: 0.21326398849487

SPRINTF: 0.33184599876404

CONCAT: 0.22434306144714

SPRINTF: 0.33112001419067

CONCAT: 0.26693606376648

SPRINTF: 0.33639192581177

CONCAT: 0.21340584754944

SPRINTF: 0.33784699440002

CONCAT: 0.22058200836182

SPRINTF: 0.33881688117981

CONCAT: 0.21394610404968

<?php
function Test5_1($format, $id, $nid) {
$t = microtime(true);
for($i = 0; $i < 1000000; ++$i){
sprintf($format, $id, $nid);
}
return (microtime(true) - $t);
}
function Test5_2($format, $id, $nid) {
$t = microtime(true);
for($i = 0; $i < 1000000; ++$i){
$url = '/debats/' . $id . '/test/' . $nid . '/bench';
}
return (microtime(true) - $t);
}
echo "\n\nSPRINTF: " . Test5_1('/debats/%s/test/%s/bench', 12, 21);
echo "\n\nCONCAT: " . Test5_2('/debats/%s/test/%s/bench', 12, 21);
echo "\n\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment