1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpMyAdmin\SqlParser\Tests\benchmarks; |
6
|
|
|
|
7
|
|
|
use PhpMyAdmin\SqlParser\UtfString; |
8
|
|
|
|
9
|
|
|
use function chr; |
10
|
|
|
use function file_get_contents; |
11
|
|
|
|
12
|
|
|
class UtfStringBench |
13
|
|
|
{ |
14
|
|
|
/** @var string */ |
15
|
|
|
private $testContents; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @BeforeMethods("setUp") |
19
|
|
|
* @Iterations(20) |
20
|
|
|
* @Revs(4) |
21
|
|
|
* @OutputTimeUnit("milliseconds") |
22
|
|
|
* @Assert("mode(variant.time.avg) < 38 milliseconds +/- 10%") |
23
|
|
|
* @Assert("mode(variant.time.avg) > 20 milliseconds +/- 10%") |
24
|
|
|
*/ |
25
|
|
|
public function benchBuildUtfString(): void |
26
|
|
|
{ |
27
|
|
|
$str1 = new UtfString($this->testContents); |
28
|
|
|
for ($i = 0; $i < $str1->length(); $i++) { |
29
|
|
|
$str1[$i];// Make offset offsetGet work |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @BeforeMethods("setUp") |
35
|
|
|
* @Iterations(2) |
36
|
|
|
* @Revs(2) |
37
|
|
|
* @OutputTimeUnit("microseconds") |
38
|
|
|
* @Assert("mode(variant.time.avg) < 75 microseconds +/- 10%") |
39
|
|
|
* @Assert("mode(variant.time.avg) > 60 microseconds +/- 10%") |
40
|
|
|
*/ |
41
|
|
|
public function benchGetCharLength(): void |
42
|
|
|
{ |
43
|
|
|
UtfString::getCharLength(chr(0x00)); // 00000000 |
44
|
|
|
UtfString::getCharLength(chr(0x7F)); // 01111111 |
45
|
|
|
|
46
|
|
|
UtfString::getCharLength(chr(0xC0)); // 11000000 |
47
|
|
|
UtfString::getCharLength(chr(0xDF)); // 11011111 |
48
|
|
|
|
49
|
|
|
UtfString::getCharLength(chr(0xE0)); // 11100000 |
50
|
|
|
UtfString::getCharLength(chr(0xEF)); // 11101111 |
51
|
|
|
|
52
|
|
|
UtfString::getCharLength(chr(0xF0)); // 11110000 |
53
|
|
|
UtfString::getCharLength(chr(0xF7)); // 11110111 |
54
|
|
|
|
55
|
|
|
UtfString::getCharLength(chr(0xF8)); // 11111000 |
56
|
|
|
UtfString::getCharLength(chr(0xFB)); // 11111011 |
57
|
|
|
|
58
|
|
|
UtfString::getCharLength(chr(0xFC)); // 11111100 |
59
|
|
|
UtfString::getCharLength(chr(0xFD)); // 11111101 |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function setUp(): void |
63
|
|
|
{ |
64
|
|
|
$contentsPath = __DIR__ . '/../../LICENSE.txt'; |
65
|
|
|
$this->testContents = (string) file_get_contents($contentsPath); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|