PHP Markdown, speed, MovableType (was "Michel Fortin")
Michael Tsai
lists at mjtsai.com
Tue Dec 7 13:48:41 EST 2004
On Dec 7, 2004, at 12:35 PM, John Gruber wrote:
> I'm fairly certain that PHP does no such caching. Each time you call
> preg_replace(), you're starting from scratch again.
Looking at the PHP source (both 4.3.8 and 5.0.2) it seems that it does
cache compiled patterns.
Also, I wrote a little PHP program:
require "markdown.php";
$s = "...long string of Markdown text...";
while (true) {
Markdown($s);
}
and ran Sampler on it. (You have to compile PHP yourself to do this;
otherwise Sampler won't have access to debugging symbols.) The result
is that 50x more time is spent in PCRE's "match" function than anywhere
else, and almost no time is spent in "pcre_get_compiled_regex." PCRE
just isn't as fast as Perl, although perhaps it's possible to tune the
patterns to make them match faster.
> Python, on the other hand, allows the programmer to optionally
> control the compilation of patterns before using them:
Also, it automatically caches a fixed number of compiled regexes, even
if you don't use re.compile.
--Michael
More information about the Markdown-discuss
mailing list