From 81c40f2190ec0aebdfde73ee69e8aae47eab98d0 Mon Sep 17 00:00:00 2001 From: Felix Becker Date: Thu, 23 Nov 2017 02:38:23 -0800 Subject: [PATCH] chore: add completion benchmark --- benchmarks/completion.php | 75 +++++++++++++++++++++++ Performance.php => benchmarks/parsing.php | 2 +- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 benchmarks/completion.php rename Performance.php => benchmarks/parsing.php (95%) diff --git a/benchmarks/completion.php b/benchmarks/completion.php new file mode 100644 index 0000000..b02d723 --- /dev/null +++ b/benchmarks/completion.php @@ -0,0 +1,75 @@ +getSize(); + $testProviderArray[] = $file->getRealPath(); + } +} + +if (count($testProviderArray) === 0) { + throw new Exception("ERROR: Validation testsuite frameworks not found - run `git submodule update --init --recursive` to download."); +} + +$index = new Index; +$definitionResolver = new DefinitionResolver($index); +$completionProvider = new CompletionProvider($definitionResolver, $index); +$docBlockFactory = DocBlockFactory::createInstance(); +$completionFile = realpath(__DIR__ . '/../validation/frameworks/symfony/src/Symfony/Component/HttpFoundation/Request.php'); +$parser = new PhpParser\Parser(); +$completionDocument = null; + +echo "Indexing $framework" . PHP_EOL; + +foreach ($testProviderArray as $idx => $testCaseFile) { + if (filesize($testCaseFile) > 100000) { + continue; + } + if ($idx % 100 === 0) { + echo $idx . '/' . count($testProviderArray) . PHP_EOL; + } + + $fileContents = file_get_contents($testCaseFile); + + try { + $d = new PhpDocument($testCaseFile, $fileContents, $index, $parser, $docBlockFactory, $definitionResolver); + if ($testCaseFile === $completionFile) { + $completionDocument = $d; + } + } catch (\Throwable $e) { + echo $e->getMessage() . PHP_EOL; + continue; + } +} + +echo "Getting completion". PHP_EOL; + +$start = microtime(true); +$list = $completionProvider->provideCompletion($completionDocument, new Position(274, 15)); +$end = microtime(true); + +echo count($list->items) . ' completion items' . PHP_EOL; + +echo "Time: " . ($end - $start) . 's' . PHP_EOL; + diff --git a/Performance.php b/benchmarks/parsing.php similarity index 95% rename from Performance.php rename to benchmarks/parsing.php index 5022f84..8eaae6a 100644 --- a/Performance.php +++ b/benchmarks/parsing.php @@ -17,7 +17,7 @@ $totalSize = 0; $frameworks = ["drupal", "wordpress", "php-language-server", "tolerant-php-parser", "math-php", "symfony", "CodeIgniter", "cakephp"]; foreach($frameworks as $framework) { - $iterator = new RecursiveDirectoryIterator(__DIR__ . "/validation/frameworks/$framework"); + $iterator = new RecursiveDirectoryIterator(__DIR__ . "/../validation/frameworks/$framework"); $testProviderArray = array(); foreach (new RecursiveIteratorIterator($iterator) as $file) {