Passed
Push — master ( 1cc25a...350129 )
by PHPinnacle
05:40 queued 02:48
created

BufferWriteBench::benchAppendString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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