1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-02 17:52:45 +01:00
psalm/tests/fixtures/performance/diff_parse_large_file.php

47 lines
1.3 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();
2019-05-29 17:58:58 +02:00
require dirname(__DIR__, 3) . '/vendor/autoload.php';
$a = file_get_contents(__DIR__ . '/a.test');
$b = file_get_contents(__DIR__ . '/b.test');
2020-08-09 22:23:43 +02:00
$a_stmts = Psalm\Internal\Provider\StatementsProvider::parseStatements($a, '7.4');
$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;
2020-03-15 04:54:42 +01:00
$traverser->addVisitor(new Psalm\Internal\PhpVisitor\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";
2020-08-09 22:23:43 +02:00
Psalm\Internal\Provider\StatementsProvider::parseStatements($b, '7.4', null, $a, $a_stmts_copy, $file_changes);
$diff_1 = microtime(true) - $time;
echo 'Partial parsing: ' . number_format($diff_1, 4) . "\n";
$time = microtime(true);
2020-08-09 22:23:43 +02:00
Psalm\Internal\Provider\StatementsProvider::parseStatements($b, '7.4');
$diff_2 = microtime(true) - $time;
echo 'Full parsing: ' . number_format($diff_2, 4) . "\n";