Skip to content
/ erbal Public
forked from ileitch/erbal

Very small, very fast Ragel/C based ERB parser

License

Notifications You must be signed in to change notification settings

ghnatiuk/erbal

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Erbal: Very small, very fast Ragel/C based ERB parser

Intro

Erbal is a lightweight ERB parser based on the Ragel State Machine Compiler (www.complang.org/ragel/) and written in C. It’s very fast.

Please note that Erbal isn’t intended as a full replacement for the ERB implementation that ships with Ruby. Erbal only implements parsing of the following tags:

<%, <%=, <%#, -%>, %>

This is to keep Erbal very simple and very fast. If there’s a good case for implementing more features from ERB and it doesn’t impact performance or add much complexity then I’ll consider it. Personally I’ve never needed anything more.

Using Erbal

require 'erbal'
e = Erbal.new("<% a=1 -%> a is: <%= a -%>", "@output_buffer")
src = e.parse
eval(src)

Rails

In your after_initialize block in config/environment.rb add:

require 'erbal/rails'
ActionView::Template.register_template_handler :erb, ErbalTemplateHandler

Benchmarks

This benchmark was performed on a MacBook Pro with a 2.4Ghz Intel Core 2 Duo and 4GB 667Mhz DDR2 SDRAM. Running Mac OS X 10.6 (Snow Leopard). The code to run it is located in benchmark/bench.rb

Summary:

Erbal is 14.6x faster than Ruby’s ERB and 7.5x faster than Erubis.

Details:

Ruby: 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10] Erubis: 2.6.5 using Erubis::FastEruby. Erbal: 0.0.2

=> Warming up.... done
=> 10000 runs repeated 6 times

=> Erb:
 1) 13.01
 2) 13.00
 3) 13.01
 4) 13.04
 5) 13.13
 6) 13.23
=> Average: 13.07

=> Erbal:
 1) 0.90
 2) 0.89
 3) 0.89
 4) 0.90
 5) 0.89
 6) 0.89
=> Average: 0.89

=> Erubis:
 1) 6.63
 2) 6.67
 3) 6.69
 4) 6.71
 5) 6.72
 6) 6.75
=> Average: 6.70

Credits

Many thanks to Adrian Thurston for writing the Ragel State Machine Compiler (www.complang.org/ragel/)!

About

Very small, very fast Ragel/C based ERB parser

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published