Passed
Pull Request — master (#506)
by
unknown
03:01
created

UtfStringBench::benchBuildUtfString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 5
rs 10
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 file_get_contents;
10
11
class UtfStringBench
12
{
13
    /** @var string */
14
    private $testContents;
15
16
    /**
17
     * @BeforeMethods("setUp")
18
     * @Iterations(20)
19
     * @Revs(4)
20
     * @OutputTimeUnit("milliseconds")
21
     * @Assert("mode(variant.time.avg) < 10 milliseconds +/- 10%")
22
     */
23
    public function benchBuildUtfString(): void
24
    {
25
        $str1 = new UtfString($this->testContents);
26
        for ($i = 0; $i < $str1->length(); $i++) {
27
            $str1[$i];// Make offset offsetGet work
28
        }
29
    }
30
31
    public function setUp(): void
32
    {
33
        $contentsPath = __DIR__ . '/../../LICENSE.txt';
34
        $this->testContents = (string) file_get_contents($contentsPath);
35
    }
36
37
    /**
38
     * @Iterations(20)
39
     * @Revs(4)
40
     * @OutputTimeUnit("microseconds")
41
     * @Assert("mode(variant.time.avg) < 100 microseconds +/- 10%")
42
     */
43
    public function benchUtfStringRandomAccessWithUnicode(): void
44
    {
45
        $text = 'abcdefghijklmnopqrstuvwxyz
46
        áéíóúýěřťǔǐǒǎšďȟǰǩľžčǚň
47
        🦋😄😃😀😊😉😍😘😚😗😂👿😮😨😱😠😡😤😖😆😋👯
48
        P\xf8\xed\xb9ern\xec \xbelu\xbbou\xe8k\xfd k\xf3d \xfap\xecl \xef\xe1belsk\xe9 k\xf3dy
49
        xℤⅿↈⅬ⅀ↆℜℝ⅗ℾ℧ⅰℓⅯⅵⅣ⅒21⅞';
50
51
        $str1 = new UtfString($text);
52
        $str1->offsetGet(10);
53
        $str1->offsetGet(100);
54
        $str1->offsetGet(20);
55
        $str1->offsetGet(0);
56
    }
57
}
58