Passed
Push — master ( 350129...e9e39b )
by PHPinnacle
02:11
created

AppendBench::benchAppendIntegers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 11
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
use PHPinnacle\Buffer\ByteBuffer;
4
5
/**
6
 * @BeforeMethods({"init"})
7
 */
8
class AppendBench
9
{
10
    /**
11
     * @var ByteBuffer
12
     */
13
    private $buffer;
14
15
    /**
16
     * @var string
17
     */
18
    private $string;
19
20
    /**
21
     * @return void
22
     */
23
    public function init(): void
24
    {
25
        $this->buffer = new ByteBuffer;
26
        $this->string = \str_repeat('str', 1000);
27
    }
28
29
    /**
30
     * @Revs(1000)
31
     * @Iterations(100)
32
     *
33
     * @return void
34
     */
35
    public function benchAppendIntegers(): void
36
    {
37
        $this->buffer
38
            ->appendInt8(1)
39
            ->appendInt16(1)
40
            ->appendInt32(1)
41
            ->appendInt64(1)
42
            ->appendUint8(1)
43
            ->appendUint16(1)
44
            ->appendUint32(1)
45
            ->appendUint64(1)
46
        ;
47
    }
48
49
    /**
50
     * @Revs(1000)
51
     * @Iterations(100)
52
     *
53
     * @return void
54
     */
55
    public function benchAppendFloats(): void
56
    {
57
        $this->buffer
58
            ->appendFloat(1.0)
59
            ->appendFloat(-1.0)
60
            ->appendFloat(\M_PI)
61
            ->appendDouble(1.0)
62
            ->appendDouble(-1.0)
63
            ->appendDouble(\M_PI)
64
        ;
65
    }
66
67
    /**
68
     * @Revs(1000)
69
     * @Iterations(100)
70
     *
71
     * @return void
72
     */
73
    public function benchAppendString(): void
74
    {
75
        $this->buffer
76
            ->append('some string')
77
            ->append("other string")
78
            ->append($this->string)
79
        ;
80
    }
81
}
82