Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Encoding: better regex performance#36

Closed
matej21 wants to merge 1 commit into
nette:masterfrom
matej21:encode_performance
Closed

Encoding: better regex performance#36
matej21 wants to merge 1 commit into
nette:masterfrom
matej21:encode_performance

Conversation

@matej21

@matej21 matej21 commented Jan 2, 2017

Copy link
Copy Markdown
Contributor

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

dg commented Jan 2, 2017

Copy link
Copy Markdown
Member

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

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

dg commented Jan 2, 2017

Copy link
Copy Markdown
Member

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants