Passed
Push — development ( 9f1fbc...c66aa5 )
by Mirco
22:08 queued 14:06
created

CBench::diff()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/***************************************************************************
3
 *  For license information see doc/license.txt
4
 *
5
 *  Unicode Reminder メモ
6
 *
7
 *  Exact time mesurement
8
 ***************************************************************************/
9
10
namespace Oc\Util;
11
12
class CBench
13
{
14
    public $start;
15
    public $stop;
16
17
    /**
18
     * CBench constructor.
19
     */
20
    public function __construct()
21
    {
22
        $this->start = 0;
23
        $this->stop = 0;
24
    }
25
26
    /**
27
     * @return float
28
     */
29
    private function getMicroTime()
30
    {
31
        list($uSec, $sec) = explode(' ', microtime());
32
33
        return ((float)$uSec + (float)$sec);
34
    }
35
36
    /**
37
     * start Benchmark
38
     */
39
    public function start()
40
    {
41
        $this->start = $this->getMicroTime();
42
    }
43
44
    /**
45
     * stop Benchmark
46
     */
47
    public function stop()
48
    {
49
        $this->stop = $this->getMicroTime();
50
    }
51
52
    /**
53
     * diff between stop and start value
54
     *
55
     * @return int
56
     */
57
    public function diff()
58
    {
59
        return $this->stop - $this->start;
60
    }
61
62
    /**
63
     * @return float
64
     */
65
    public function runTime()
66
    {
67
        return $this->getMicroTime() - $this->start;
68
    }
69
}
70