ZF-227: regex pattern in Zend_Json_Decode::_eatWhitespace() method

Issue Type: Improvement Created: 2006-07-11T19:39:08.000+0000 Last Updated: 2007-07-05T14:43:13.000+0000 Status: Resolved Fix version(s): - 0.2.0 (29/Oct/06)

Reporter: Naoto Ishikawa (ishinao) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Json

Related issues: Attachments:


It is written using following regular expression code. '/(\t|\b|\f|\n|\r| )/s' But I think it's better to change like this, if it means the same. '/[\t\b\f\n\r ]/s'

# regular expression using pipe is too slow

// Sample benchmark code $text = 'abc a b c abcde fghij'; $pattern1 = '/(\t|\b|\f|\n|\r| )/s'; $pattern2 = '/[\t\b\f\n\r ]/s'; $time = microtime(true); for ($i = 0; $i < 100000; $i ++) { preg_match($pattern1, $text); } echo $pattern1 .': ' . (microtime(true) - $time) . "\n";

$time = microtime(true); for ($i = 0; $i < 100; $i ++) { preg_match($pattern2, $text); }

echo $pattern2 .': ' . (microtime(true) - $time) . "\n";

Result: /(\t|\b|\f|\n|\r| )/s: 3.1665399074554 /[\t\b\f\n\r ]/s: 0.0034799575805664


Posted by Matthew Weier O'Phinney (matthew) on 2006-07-28T11:45:50.000+0000

Fixed in commit 926

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.