comparison vendor/psy/psysh/src/Command/TimeitCommand.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents c2387f117808
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
14 use PhpParser\NodeTraverser; 14 use PhpParser\NodeTraverser;
15 use PhpParser\PrettyPrinter\Standard as Printer; 15 use PhpParser\PrettyPrinter\Standard as Printer;
16 use Psy\Command\TimeitCommand\TimeitVisitor; 16 use Psy\Command\TimeitCommand\TimeitVisitor;
17 use Psy\Input\CodeArgument; 17 use Psy\Input\CodeArgument;
18 use Psy\ParserFactory; 18 use Psy\ParserFactory;
19 use Psy\Shell;
20 use Symfony\Component\Console\Input\InputInterface; 19 use Symfony\Component\Console\Input\InputInterface;
21 use Symfony\Component\Console\Input\InputOption; 20 use Symfony\Component\Console\Input\InputOption;
22 use Symfony\Component\Console\Output\OutputInterface; 21 use Symfony\Component\Console\Output\OutputInterface;
23 22
24 /** 23 /**
97 96
98 $times = self::$times; 97 $times = self::$times;
99 self::$times = []; 98 self::$times = [];
100 99
101 if ($num === 1) { 100 if ($num === 1) {
102 $output->writeln(sprintf(self::RESULT_MSG, $times[0])); 101 $output->writeln(\sprintf(self::RESULT_MSG, $times[0]));
103 } else { 102 } else {
104 $total = array_sum($times); 103 $total = \array_sum($times);
105 rsort($times); 104 \rsort($times);
106 $median = $times[round($num / 2)]; 105 $median = $times[\round($num / 2)];
107 106
108 $output->writeln(sprintf(self::AVG_RESULT_MSG, $total / $num, $median, $total)); 107 $output->writeln(\sprintf(self::AVG_RESULT_MSG, $total / $num, $median, $total));
109 } 108 }
110 } 109 }
111 110
112 /** 111 /**
113 * Internal method for marking the start of timeit execution. 112 * Internal method for marking the start of timeit execution.
116 * input code to instrument the call. We will use the saved start time to 115 * input code to instrument the call. We will use the saved start time to
117 * more accurately calculate time elapsed during execution. 116 * more accurately calculate time elapsed during execution.
118 */ 117 */
119 public static function markStart() 118 public static function markStart()
120 { 119 {
121 self::$start = microtime(true); 120 self::$start = \microtime(true);
122 } 121 }
123 122
124 /** 123 /**
125 * Internal method for marking the end of timeit execution. 124 * Internal method for marking the end of timeit execution.
126 * 125 *
135 * 134 *
136 * @return mixed it just passes $ret right back 135 * @return mixed it just passes $ret right back
137 */ 136 */
138 public static function markEnd($ret = null) 137 public static function markEnd($ret = null)
139 { 138 {
140 self::$times[] = microtime(true) - self::$start; 139 self::$times[] = \microtime(true) - self::$start;
141 self::$start = null; 140 self::$start = null;
142 141
143 return $ret; 142 return $ret;
144 } 143 }
145 144
183 $code = '<?php ' . $code; 182 $code = '<?php ' . $code;
184 183
185 try { 184 try {
186 return $this->parser->parse($code); 185 return $this->parser->parse($code);
187 } catch (\PhpParser\Error $e) { 186 } catch (\PhpParser\Error $e) {
188 if (strpos($e->getMessage(), 'unexpected EOF') === false) { 187 if (\strpos($e->getMessage(), 'unexpected EOF') === false) {
189 throw $e; 188 throw $e;
190 } 189 }
191 190
192 // If we got an unexpected EOF, let's try it again with a semicolon. 191 // If we got an unexpected EOF, let's try it again with a semicolon.
193 return $this->parser->parse($code . ';'); 192 return $this->parser->parse($code . ';');