Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of phpunit/php-timer.
4
 *
5
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace SebastianBergmann\Timer;
11
 
12
use function array_pop;
13
use function hrtime;
14
 
15
final class Timer
16
{
17
    /**
18
     * @psalm-var list<float>
19
     */
20
    private $startTimes = [];
21
 
22
    public function start(): void
23
    {
24
        $this->startTimes[] = (float) hrtime(true);
25
    }
26
 
27
    /**
28
     * @throws NoActiveTimerException
29
     */
30
    public function stop(): Duration
31
    {
32
        if (empty($this->startTimes)) {
33
            throw new NoActiveTimerException(
34
                'Timer::start() has to be called before Timer::stop()'
35
            );
36
        }
37
 
38
        return Duration::fromNanoseconds((float) hrtime(true) - array_pop($this->startTimes));
39
    }
40
}