-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Labels
Description
Thanks for your awesome project.
Can we improve performance by replacing tokenize to token_get_all ?
tinpont@local:~/expression-test$ php -f compare.php
token_get_all: 0.077315092086792
StringCalc: 2.0649530887604Source code:
<?php
require 'vendor/autoload.php';
$limit = 100000;
$expression = 'INT(W*0.013)*0.014';
$startTime = microtime(true);
for ($i = 0; $i < $limit; $i ++) {
$tokens = token_get_all("<?php $expression;");
}
echo 'token_get_all: ' . (microtime(true) - $startTime) . PHP_EOL;
$stringCalc = new ChrisKonnertz\StringCalc\StringCalc();
$startTime = microtime(true);
for ($i = 0; $i < $limit; $i ++) {
$tokens = $stringCalc->tokenize($expression);
}
echo 'StringCalc: ' . (microtime(true) - $startTime) . PHP_EOL;