Created
February 21, 2018 18:52
-
-
Save dmaicher/ae506ff436a4647f3eaf7e59ec4c4aa1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'vendor/autoload.php'; | |
$expressionLang = new \Symfony\Component\Security\Core\Authorization\ExpressionLanguage( | |
new \Symfony\Component\Cache\Adapter\NullAdapter() | |
); | |
$iterations = 500000; | |
$rawExpression = "1 in [1, 2, 3, 4] and (1 == 2 or 1 > 2 or 'foo' in ['bar', 'foo'])"; | |
$expression = new \Symfony\Component\ExpressionLanguage\Expression($rawExpression); | |
$time = microtime(true); | |
foreach (range(0, $iterations) as $i) { | |
$expressionLang->evaluate($expression); | |
} | |
echo "raw: " . (microtime(true) - $time) . "s \n"; | |
$parsedExpression = $expressionLang->parse($rawExpression, []); | |
$expression = new \Symfony\Component\ExpressionLanguage\SerializedParsedExpression( | |
$rawExpression, | |
serialize($parsedExpression->getNodes()) | |
); | |
$time = microtime(true); | |
foreach (range(0, $iterations) as $i) { | |
$expressionLang->evaluate($expression); | |
} | |
echo "parsed: " . (microtime(true) - $time) . "s \n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment