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

ConsumeBench::benchConsume()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 16
nc 1
nop 0
dl 0
loc 18
rs 9.7333
c 1
b 0
f 0
1
<?php
2
3
use PHPinnacle\Buffer\ByteBuffer;
4
5
/**
6
 * @BeforeMethods({"init"})
7
 */
8
class ConsumeBench
9
{
10
    /**
11
     * @var ByteBuffer
12
     */
13
    private $buffer;
14
15
    /**
16
     * @var int
17
     */
18
    private $revs = 1000;
19
20
    /**
21
     * @return void
22
     */
23
    public function init(): void
24
    {
25
        $this->buffer = new ByteBuffer;
26
27
        for ($i = 0; $i < $this->revs; ++$i) {
28
            $this->buffer
29
                ->appendInt8(1)
30
                ->appendInt16(1)
31
                ->appendInt32(1)
32
                ->appendInt64(1)
33
                ->appendUint8(1)
34
                ->appendUint16(1)
35
                ->appendUint32(1)
36
                ->appendUint64(1)
37
                ->appendFloat(1.1)
38
                ->appendFloat(-1.1)
39
                ->appendFloat(\M_PI)
40
                ->appendDouble(1.1)
41
                ->appendDouble(-1.1)
42
                ->appendDouble(\M_PI)
43
                ->append('some string')
44
                ->append("other string")
45
            ;
46
        }
47
    }
48
49
    /**
50
     * @Revs(1000)
51
     * @Iterations(100)
52
     *
53
     * @return void
54
     */
55
    public function benchConsume(): void
56
    {
57
        $this->buffer->consumeInt8();
58
        $this->buffer->consumeInt16();
59
        $this->buffer->consumeInt32();
60
        $this->buffer->consumeInt64();
61
        $this->buffer->consumeUint8();
62
        $this->buffer->consumeUint16();
63
        $this->buffer->consumeUint32();
64
        $this->buffer->consumeUint64();
65
        $this->buffer->consumeFloat();
66
        $this->buffer->consumeFloat();
67
        $this->buffer->consumeFloat();
68
        $this->buffer->consumeDouble();
69
        $this->buffer->consumeDouble();
70
        $this->buffer->consumeDouble();
71
        $this->buffer->consume(11);
72
        $this->buffer->consume(12);
73
    }
74
}
75