1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-11 08:49:52 +01:00
psalm/tests/performance/diff_parse_large_file.php

51 lines
1.4 KiB
PHP
Raw Normal View History

<?php
ini_set('display_startup_errors', '1');
ini_set('html_errors', '1');
2019-01-02 17:18:22 +01:00
ini_set('memory_limit', '4G');
error_reporting(E_ALL);
gc_disable();
require __DIR__ . '../../../vendor/autoload.php';
$a = file_get_contents(__DIR__ . '/a.test');
$b = file_get_contents(__DIR__ . '/b.test');
2018-11-06 03:57:36 +01:00
$a_stmts = Psalm\Internal\Provider\StatementsProvider::parseStatements($a);
$time = microtime(true);
2018-11-06 03:57:36 +01:00
$file_changes = Psalm\Internal\Diff\FileDiffer::getDiff($a, $b);
$dlt = microtime(true);
$line_diff_time = $dlt - $time;
echo 'Partial parsing: diffing lines: ' . number_format($line_diff_time, 4) . "\n";
$traverser = new PhpParser\NodeTraverser;
2018-11-06 03:57:36 +01:00
$traverser->addVisitor(new Psalm\Internal\Visitor\CloningVisitor);
// performs a deep clone
/** @var array<int, PhpParser\Node\Stmt> */
$a_stmts_copy = $traverser->traverse($a_stmts);
$dlt2 = microtime(true);
echo 'Partial parsing: cloning: ' . number_format($dlt2 - $dlt, 4) . "\n";
2018-11-06 03:57:36 +01:00
Psalm\Internal\Provider\StatementsProvider::parseStatements($b, null, $a, $a_stmts_copy, $file_changes);
$diff_1 = microtime(true) - $time;
echo 'Partial parsing: ' . number_format($diff_1, 4) . "\n";
$time = microtime(true);
2018-11-06 03:57:36 +01:00
Psalm\Internal\Provider\StatementsProvider::parseStatements($b);
$diff_2 = microtime(true) - $time;
echo 'Full parsing: ' . number_format($diff_2, 4) . "\n";
2019-01-02 17:18:22 +01:00
echo strlen($a);
Psalm\Internal\Diff\FileDiffer::getDiff($a, '');