- mb_check_encoding: documentation ( source)
- microtime: documentation ( source)
- preg_match: documentation ( source)
- base64_encode: documentation ( source)
- random_bytes: documentation ( source)
- printf: documentation ( source)
<?php
printf("%s\n", PHP_VERSION);
echo "\n";
$data = [];
$i = 1000;
$byteLength = 10000;
while ($i--) {
$data[] = base64_encode(random_bytes($byteLength));
}
// PCRE
$max = 100;
$start = microtime(true);
for ($c = 0; $c < $max; $c++) {
for ($i = 0; $i < 1000; $i++) {
$value = $data[$i];
false !== preg_match('~~u', $value);
}
}
printf("Took %.7f seconds per execution\n", (microtime(true) - $start) / $max);
echo "\n";
// mbstring
$max = 100;
$start = microtime(true);
for ($c = 0; $c < $max; $c++) {
for ($i = 0; $i < 1000; $i++) {
$value = $data[$i];
false !== mb_check_encoding($value, 'UTF-8');
}
}
printf("Took %.7f seconds per execution\n", (microtime(true) - $start) / $max);