Ragel success story

Wincent Colaiuta w... at wincent.com
Mon Feb 4 20:40:48 UTC 2008


Here's a little Ragel success story.

I've written a wikitext-to-HTML translator written in C (a Ruby
extension) and up until a few days ago it was using a lexer generated
by ANTLR 3.0.1 (the C target). I've had a suspicion for some time,
however, that a Ragel scanner might be faster for a number of reasons.

Imagine my surprise when I compared the speed and found that Ragel was
nearly 10 times faster! I hadn't been expecting that kind of
improvement.

You can look at the code here:

http://git.wincent.com/wikitext.git

And an article with the benchmark results is here:

http://wincent.com/a/about/wincent/weblog/archives/2008/02/ragel_wins_fata.php

For comparison, the current version of the ANTLR grammar at the time
of writing is:

http://git.wincent.com/wikitext.git?a=blob;f=ext/Wikitext.g;h=642f275cd36d0a0f28c1bf8fc2f859658a0e1a81;hb=antlr

And the corresponding Ragel scanner implementation is:

http://git.wincent.com/wikitext.git?a=blob;f=ext/wikitext_ragel.rl;h=a82a304632826370041639ed0d9d9c085faeda98;hb=bd7799aa1938f36f65b2523b47f1202eac3b31bf

I've made no attempt at optimization yet, but the performance of the
Ragel scanner is already spectacular for a "rough draft".

Ragel is a wonderful tool!

Cheers,
Wincent



More information about the ragel-users mailing list