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

Encoding: better regex performance #36

Closed
wants to merge 1 commit into from

Conversation

@matej21
Copy link
Contributor

matej21 commented Jan 2, 2017

see matej21/neon-js#3

This regex may become very slow in a combination with end of string assertion

see this and this and compare number of steps (it increases exponentially)

Performance test:

$encoder = new \Nette\Neon\Encoder();
$var = str_repeat('a', 20) . ',';

$start = microtime(TRUE);
for ($i = 0; $i < 1000; $i++) {
	$encoder->encode($var);
}
echo microtime(TRUE) - $start;
echo "\n";

before: 3.8s
now: 0.005s

thanks @JirkaVebr for a help

@dg

This comment has been minimized.

Copy link
Member

dg commented Jan 2, 2017

https://regex101.com is awesome! Where it was my whole life?

@dg dg closed this in 3a2f839 Jan 2, 2017
@dg

This comment has been minimized.

Copy link
Member

dg commented Jan 2, 2017

I hope this fix will work 3a2f839

dg added a commit that referenced this pull request Jan 2, 2017
dg added a commit that referenced this pull request Jan 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.