Skip to content

Instantly share code, notes, and snippets.

@dmaicher
Created February 21, 2018 18:52
Show Gist options
  • Save dmaicher/ae506ff436a4647f3eaf7e59ec4c4aa1 to your computer and use it in GitHub Desktop.
Save dmaicher/ae506ff436a4647f3eaf7e59ec4c4aa1 to your computer and use it in GitHub Desktop.
<?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