It would be awesome if we could replace XHPAST with a pure PHP implementation such as nikic/PHP-Parser.
Description
Description
Revisions and Commits
Revisions and Commits
Related Objects
Related Objects
Event Timeline
Comment Actions
Here's a very basic test I did for profiling XHPAST against PHP-Parser:
<?php require_once __DIR__.'/scripts/__init_script__.php'; require_once '/home/joshua/.composer/vendor/autoload.php'; function parse_nikic($data) { $parser = new PhpParser\Parser(new PhpParser\Lexer()); try { return $parser->parse($data); } catch (PhpParser\Error $e) { echo 'Parse Error: '.$e->getMessage()."\n"; } } function parse_nikic_emulated($data) { $parser = new PhpParser\Parser(new PhpParser\Lexer\Emulative()); try { return $parser->parse($data); } catch (PhpParser\Error $e) { echo 'Parse Error: '.$e->getMessage()."\n"; } } function parse_xhpast($data) { try { $future = xhpast_get_parser_future($data); XHPASTTree::newFromDataAndResolvedExecFuture($data, $future->resolve()); } catch (XHPASTSyntaxErrorException $e) { echo 'Parse Error: '.$e->getMessage()."\n"; } } $code = <<<'EOPHP' // Massive amount of PHP goes here EOPHP ; $start = microtime(true); parse_nikic($code); $end = microtime(true); echo 'parse_nikic() took '.($end - $start)."us\n"; $start = microtime(true); parse_nikic_emulated($code); $end = microtime(true); echo 'parse_nikic_emulated() took '.($end - $start)."us\n"; $start = microtime(true); parse_xhpast($code); $end = microtime(true); echo 'parse_xhpast() took '.($end - $start)."us\n";
The output for a ~5500 line PHP file is as follows:
parse_nikic() took 0.94200587272644us parse_nikic_emulated() took 1.162672996521us parse_xhpast() took 0.84375190734863us