- chr: documentation ( source)
- base_convert: documentation ( source)
- microtime: documentation ( source)
- array_shift: documentation ( source)
- str_pad: documentation ( source)
- unpack: documentation ( source)
<?php
$time_start = microtime(true);
$test1 = '';
for($t=0; $t<10; $t++)
{
for($i=0; $i<255; $i++)
{
$tmp = unpack('H*', chr($i));
$test1 .= '\\x'.array_shift($tmp);
}
}
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "$time seconds\n";
$time_start = microtime(true);
$test2 = '';
for($t=0; $t<10; $t++)
{
for($i=0; $i<255; $i++)
{
$test2 .= '\\x'.str_pad(base_convert($i, 10, 16), 2, 0, STR_PAD_LEFT);
}
}
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "$time seconds\n";
echo ($test1 === $test2) ? 'OK' : 'NOT OK';
?>