Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improve] use token_get_all instead of tokenize method #15

Open
tinpont opened this issue Aug 29, 2018 · 2 comments
Open

[Improve] use token_get_all instead of tokenize method #15

tinpont opened this issue Aug 29, 2018 · 2 comments
Assignees

Comments

@tinpont
Copy link

tinpont commented Aug 29, 2018

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.0649530887604

Source 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;
@chriskonnertz
Copy link
Owner

Hello,
did you experience actual performance issues when using this library?

@tinpont
Copy link
Author

tinpont commented Aug 30, 2018

In fact it did not. But I think that it still have a chance to improve performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants