<?php
echo $p = implode('', range('a', 'z'));
echo PHP_EOL;
echo $c = substr($p, 13);
echo PHP_EOL;
$times = 1000 * 10 * 10;
$test = function() use($p, $c)
{
return substr($p, 0, strlen($c)) == $c;
};
$test1 = function() use ($p, $c)
{
return strncmp($p, $c, strlen($c));
};
$print = function($closure, $s) use ($times)
{
for ($i =0; $i < $times; $i++)
$closure();
echo printf('Runns: %01.2f', microtime(1) - $s);
echo PHP_EOL;
};
$print($test, microtime(1));
$print($test1, microtime(1));
preferences:
38.23 ms | 402 KiB | 5 Q