Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 200 | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 200 Revision 1663
Zeile 26... Zeile 26...
26
class TimeitCommand extends Command
26
class TimeitCommand extends Command
27
{
27
{
28
    const RESULT_MSG = '<info>Command took %.6f seconds to complete.</info>';
28
    const RESULT_MSG = '<info>Command took %.6f seconds to complete.</info>';
29
    const AVG_RESULT_MSG = '<info>Command took %.6f seconds on average (%.6f median; %.6f total) to complete.</info>';
29
    const AVG_RESULT_MSG = '<info>Command took %.6f seconds on average (%.6f median; %.6f total) to complete.</info>';
Zeile -... Zeile 30...
-
 
30
 
-
 
31
    // All times stored as nanoseconds!
30
 
32
    private static $useHrtime;
31
    private static $start = null;
33
    private static $start = null;
Zeile 32... Zeile 34...
32
    private static $times = [];
34
    private static $times = [];
33
 
35
 
Zeile 38... Zeile 40...
38
    /**
40
    /**
39
     * {@inheritdoc}
41
     * {@inheritdoc}
40
     */
42
     */
41
    public function __construct($name = null)
43
    public function __construct($name = null)
42
    {
44
    {
-
 
45
        // @todo Remove microtime use after we drop support for PHP < 7.3
-
 
46
        self::$useHrtime = \function_exists('hrtime');
-
 
47
 
43
        $parserFactory = new ParserFactory();
48
        $parserFactory = new ParserFactory();
44
        $this->parser = $parserFactory->createParser();
49
        $this->parser = $parserFactory->createParser();
Zeile 45... Zeile 50...
45
 
50
 
46
        $this->traverser = new NodeTraverser();
51
        $this->traverser = new NodeTraverser();
Zeile 98... Zeile 103...
98
 
103
 
99
        $times = self::$times;
104
        $times = self::$times;
Zeile 100... Zeile 105...
100
        self::$times = [];
105
        self::$times = [];
101
 
106
 
102
        if ($num === 1) {
107
        if ($num === 1) {
103
            $output->writeln(\sprintf(self::RESULT_MSG, $times[0]));
108
            $output->writeln(\sprintf(self::RESULT_MSG, $times[0] / 1e+9));
104
        } else {
109
        } else {
105
            $total = \array_sum($times);
110
            $total = \array_sum($times);
Zeile 106... Zeile 111...
106
            \rsort($times);
111
            \rsort($times);
107
            $median = $times[\round($num / 2)];
112
            $median = $times[\round($num / 2)];
Zeile 108... Zeile 113...
108
 
113
 
109
            $output->writeln(\sprintf(self::AVG_RESULT_MSG, $total / $num, $median, $total));
114
            $output->writeln(\sprintf(self::AVG_RESULT_MSG, ($total / $num) / 1e+9, $median / 1e+9, $total / 1e+9));
Zeile 119... Zeile 124...
119
     * input code to instrument the call. We will use the saved start time to
124
     * input code to instrument the call. We will use the saved start time to
120
     * more accurately calculate time elapsed during execution.
125
     * more accurately calculate time elapsed during execution.
121
     */
126
     */
122
    public static function markStart()
127
    public static function markStart()
123
    {
128
    {
124
        self::$start = \microtime(true);
129
        self::$start = self::$useHrtime ? \hrtime(true) : (\microtime(true) * 1e+6);
125
    }
130
    }
Zeile 126... Zeile 131...
126
 
131
 
127
    /**
132
    /**
128
     * Internal method for marking the end of timeit execution.
133
     * Internal method for marking the end of timeit execution.
Zeile 138... Zeile 143...
138
     *
143
     *
139
     * @return mixed it just passes $ret right back
144
     * @return mixed it just passes $ret right back
140
     */
145
     */
141
    public static function markEnd($ret = null)
146
    public static function markEnd($ret = null)
142
    {
147
    {
143
        self::$times[] = \microtime(true) - self::$start;
148
        self::$times[] = (self::$useHrtime ? \hrtime(true) : (\microtime(true) * 1e+6)) - self::$start;
144
        self::$start = null;
149
        self::$start = null;
Zeile 145... Zeile 150...
145
 
150
 
146
        return $ret;
151
        return $ret;