Browse Source

Changed performance test data

labels
J. King 6 years ago
parent
commit
e755699dd7
  1. 2
      RoboFile.php
  2. 30
      perf/perf.php

2
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");

30
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;
}
}

Loading…
Cancel
Save