mirror of
https://github.com/danog/PHP-Parser.git
synced 2024-11-27 04:14:44 +01:00
Measure time spent in parser, pretty printer and comparison
This commit is contained in:
parent
cf3afca97d
commit
5e91c622cc
@ -16,14 +16,15 @@ echo '<table>
|
|||||||
<tr>
|
<tr>
|
||||||
<td>File</td>
|
<td>File</td>
|
||||||
<td>Parse</td>
|
<td>Parse</td>
|
||||||
<td>Time</td>
|
|
||||||
<td>PrettyPrint</td>
|
<td>PrettyPrint</td>
|
||||||
<td>Compare</td>
|
<td>Compare</td>
|
||||||
</tr>';
|
</tr>';
|
||||||
|
|
||||||
$totalStartTime = microtime(true);
|
|
||||||
$parseFail = $parseCount = $ppFail = $ppCount = $compareFail = $compareCount = 0;
|
$parseFail = $parseCount = $ppFail = $ppCount = $compareFail = $compareCount = 0;
|
||||||
|
|
||||||
|
$totalStartTime = microtime(true);
|
||||||
|
$parseTime = $ppTime = $compareTime = 0;
|
||||||
|
|
||||||
foreach (new RecursiveIteratorIterator(
|
foreach (new RecursiveIteratorIterator(
|
||||||
new RecursiveDirectoryIterator($DIR),
|
new RecursiveDirectoryIterator($DIR),
|
||||||
RecursiveIteratorIterator::LEAVES_ONLY)
|
RecursiveIteratorIterator::LEAVES_ONLY)
|
||||||
@ -39,41 +40,44 @@ foreach (new RecursiveIteratorIterator(
|
|||||||
set_time_limit(10);
|
set_time_limit(10);
|
||||||
|
|
||||||
$errMsg = '';
|
$errMsg = '';
|
||||||
$startTime = microtime(true);
|
|
||||||
|
|
||||||
|
++$parseCount;
|
||||||
|
$parseTime -= microtime(true);
|
||||||
$stmts = $parser->parse(
|
$stmts = $parser->parse(
|
||||||
new Lexer(file_get_contents($file)),
|
new Lexer(file_get_contents($file)),
|
||||||
function($msg) use (&$errMsg) {
|
function ($msg) use (&$errMsg) {
|
||||||
$errMsg = $msg;
|
$errMsg = $msg;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
$parseTime += microtime(true);
|
||||||
|
|
||||||
$time = microtime(true) - $startTime;
|
|
||||||
|
|
||||||
++$parseCount;
|
|
||||||
if (false !== $stmts) {
|
if (false !== $stmts) {
|
||||||
|
++$ppCount;
|
||||||
|
$ppTime -= microtime(true);
|
||||||
$code = '<?php' . "\n" . $prettyPrinter->pStmts($stmts);
|
$code = '<?php' . "\n" . $prettyPrinter->pStmts($stmts);
|
||||||
|
$ppTime += microtime(true);
|
||||||
|
|
||||||
$ppStmts = $parser->parse(
|
$ppStmts = $parser->parse(
|
||||||
new Lexer($code),
|
new Lexer($code),
|
||||||
function($msg) use (&$errMsg) {
|
function ($msg) use (&$errMsg) {
|
||||||
$errMsg = $msg;
|
$errMsg = $msg;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
++$ppCount;
|
|
||||||
if (false !== $ppStmts) {
|
if (false !== $ppStmts) {
|
||||||
++$compareCount;
|
++$compareCount;
|
||||||
if ($nodeDumper->dump($stmts) == $nodeDumper->dump($ppStmts)) {
|
$compareTime -= microtime(true);
|
||||||
|
$same = $nodeDumper->dump($stmts) == $nodeDumper->dump($ppStmts);
|
||||||
|
$compareTime += microtime(true);
|
||||||
|
|
||||||
|
if ($same) {
|
||||||
echo '
|
echo '
|
||||||
<td class="pass">PASS</td>
|
<td class="pass">PASS</td>
|
||||||
<td>' . $time . 's</td>
|
|
||||||
<td class="pass">PASS</td>
|
<td class="pass">PASS</td>
|
||||||
<td class="pass">PASS</td>
|
<td class="pass">PASS</td>
|
||||||
</tr>'; } else {
|
</tr>'; } else {
|
||||||
echo '
|
echo '
|
||||||
<td class="pass">PASS</td>
|
<td class="pass">PASS</td>
|
||||||
<td>' . $time . 's</td>
|
|
||||||
<td class="pass">PASS</td>
|
<td class="pass">PASS</td>
|
||||||
<td class="fail">FAIL</td>
|
<td class="fail">FAIL</td>
|
||||||
</tr>';
|
</tr>';
|
||||||
@ -83,7 +87,6 @@ foreach (new RecursiveIteratorIterator(
|
|||||||
} else {
|
} else {
|
||||||
echo '
|
echo '
|
||||||
<td class="pass">PASS</td>
|
<td class="pass">PASS</td>
|
||||||
<td>' . $time . 's</td>
|
|
||||||
<td class="fail">FAIL</td>
|
<td class="fail">FAIL</td>
|
||||||
<td></td>
|
<td></td>
|
||||||
</tr>';
|
</tr>';
|
||||||
@ -93,7 +96,6 @@ foreach (new RecursiveIteratorIterator(
|
|||||||
} else {
|
} else {
|
||||||
echo '
|
echo '
|
||||||
<td class="fail">FAIL</td>
|
<td class="fail">FAIL</td>
|
||||||
<td>' . $time . 's</td>
|
|
||||||
<td></td>
|
<td></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -109,10 +111,16 @@ echo '
|
|||||||
<tr>
|
<tr>
|
||||||
<td>Fail / Total:</td>
|
<td>Fail / Total:</td>
|
||||||
<td><span class="failCount">' . $parseFail . '</span> / ' . $parseCount . '</td>
|
<td><span class="failCount">' . $parseFail . '</span> / ' . $parseCount . '</td>
|
||||||
<td></td>
|
|
||||||
<td><span class="failCount">' . $ppFail . '</span> / ' . $ppCount . '</td>
|
<td><span class="failCount">' . $ppFail . '</span> / ' . $ppCount . '</td>
|
||||||
<td><span class="failCount">' . $compareFail . '</span> / ' . $compareCount . '</td>
|
<td><span class="failCount">' . $compareFail . '</span> / ' . $compareCount . '</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Time:</td>
|
||||||
|
<td>' . $parseTime . '</td>
|
||||||
|
<td>' . $ppTime . '</td>
|
||||||
|
<td>' . $compareTime . '</td>
|
||||||
|
</tr>
|
||||||
</table>';
|
</table>';
|
||||||
|
|
||||||
echo 'Total time: ', microtime(true) - $totalStartTime;
|
echo 'Total time: ', microtime(true) - $totalStartTime, '<br />',
|
||||||
|
'Maximum memory usage: ', memory_get_peak_usage(true);
|
Loading…
Reference in New Issue
Block a user