Good Code More Important
So, if you think this kind of thing is important, keep in mind that it's a constant in Big O. To put it another way, database calls, On2 or worse activities are the only things that matter. In most cases, it's futile to spend time worrying about these low-level commands.
Not to imply that constants should be ignored; for example, I refactored code that gathered images since it did so one at a time, each taking 1 second, and it decreased the duration from 12 seconds to 1 second (using multi curl request). The idea is that built-in commands are low-level, and the code structure is more crucial.
The code below makes 10 million lower level calls, and as you can see the "savings" are negligible.
function prof_flag($str)
{
global $prof_timing, $prof_names;
$prof_timing[] = microtime(true);
$prof_names[] = $str;
}
function prof_print()
{
global $prof_timing, $prof_names;
$size = count($prof_timing);
for($i=0;$i<$size - 1; $i++)
{
echo "<b>{$prof_names[$i]}</b><br>";
echo sprintf(" %f<br>", $prof_timing[$i+1]-$prof_timing[$i]);
}
echo "<b>{$prof_names[$size-1]}</b><br>";
}
$l = 10000000;
$str = "the quick brown fox";
echo "<h3>Ran " .number_format($l,2) ." calls per command </h3>";
prof_flag("Start: stripos");
for ($i = 0; $i<$l; $i++)
if (stripos($str, 'fox') !== false) {}
prof_flag("Start: preg_match");
for ($i = 0; $i<$l; $i++)
if (preg_match('#fox#i', $str) === 1) {}
prof_flag("Finished");
prof_print();
Only value to this code is that it shows a cool way to record times things take to run lol
Ran 10,000,000.00 calls per command
Start: stripos
2.217225
Start: preg_match
3.788667
Start: ==
0.511315
Start: ucwords lol
2.112984
Finished