diff --git a/RoboFile.php b/RoboFile.php index 6a032af..5cef158 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -63,7 +63,7 @@ class RoboFile extends \Robo\Tasks { /** Runs a performance evaluation. * * The performance of the library's basic functionality is tested against - * both IntlCodePointBreakIterator and preg_split + * the IntlCodePointBreakIterator class */ public function perf(array $args): Result { $execpath = realpath(self::BASE."perf/perf.php"); diff --git a/perf/perf.php b/perf/perf.php index e899a12..2dcb912 100644 --- a/perf/perf.php +++ b/perf/perf.php @@ -9,8 +9,8 @@ namespace MensBeam\UTF8; require __DIR__."/../tests/bootstrap.php"; $files = [ - 'HTML specification in English' => ["https://html.spec.whatwg.org/", "html-en.html"], - 'HTML specification in Chinese' => ["https://whatwg-cn.github.io/html/", "html-zh.html"], + 'ASCII text' => ["ascii.txt", false, 0, 0x7F], + 'Multi-byte text' => ["multi.txt", false, 0x80, 0x10FFFF], ]; $tests = [ @@ -51,10 +51,10 @@ if (!file_exists(__DIR__."/docs/")) { } foreach($files as $fName => $file) { - list($url, $file) = $file; + list($file, $binary, $min, $max) = $file; $file = __DIR__."/docs/$file"; if (!file_exists($file)) { - $text = file_get_contents($url); + $text = gen_string(1000000, $binary, $min, $max); file_put_contents($file, $text); } else { $text = file_get_contents($file); @@ -77,3 +77,25 @@ foreach($files as $fName => $file) { } } } + +function gen_string(int $size, bool $binary, int $lowest, int $highest): string { + $a = 0; + $out = ""; + if ($binary) { + while ($a++ < $size) { + $c = chr(mt_rand(0, 255)); + $out = "$out$c"; + } + return $out; + } else { + while ($a++ < $size) { + $p = mt_rand($lowest, $highest); + if ($p >= 55296 && $p <= 57343) { + $p = 0xFFFD; + } + $c = \IntlChar::chr($p); + $out = "$out$c"; + } + return $out; + } +}