-
-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathUtfStringBench.php
57 lines (48 loc) · 1.57 KB
/
UtfStringBench.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\benchmarks;
use PhpMyAdmin\SqlParser\UtfString;
use function file_get_contents;
class UtfStringBench
{
private string $testContents = '';
/**
* @BeforeMethods("setUp")
* @Iterations(20)
* @Revs(4)
* @OutputTimeUnit("milliseconds")
* @Assert("mode(variant.time.avg) < 40 milliseconds +/- 10%")
*/
public function benchBuildUtfString(): void
{
$str1 = new UtfString($this->testContents);
for ($i = 0; $i < $str1->length(); $i++) {
// @phpstan-ignore-next-line
$str1[$i]; // Make offset offsetGet work
}
}
public function setUp(): void
{
$contentsPath = __DIR__ . '/../../LICENSE.txt';
$this->testContents = (string) file_get_contents($contentsPath);
}
/**
* @Iterations(20)
* @Revs(4)
* @OutputTimeUnit("microseconds")
* @Assert("mode(variant.time.avg) < 120 microseconds +/- 10%")
*/
public function benchUtfStringRandomAccessWithUnicode(): void
{
$text = 'abcdefghijklmnopqrstuvwxyz
áéíóúýěřťǔǐǒǎšďȟǰǩľžčǚň
🦋😄😃😀😊😉😍😘😚😗😂👿😮😨😱😠😡😤😖😆😋👯
P\xf8\xed\xb9ern\xec \xbelu\xbbou\xe8k\xfd k\xf3d \xfap\xecl \xef\xe1belsk\xe9 k\xf3dy
xℤⅿↈⅬ⅀ↆℜℝ⅗ℾ℧ⅰℓⅯⅵⅣ⅒21⅞';
$str1 = new UtfString($text);
$str1->offsetGet(10);
$str1->offsetGet(100);
$str1->offsetGet(20);
$str1->offsetGet(0);
}
}