lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


for the last year I was working on a little lua http application server
which due to some injuries never really got of the ground. However, one
of the outcomes is an XML based templating engine targetting HTML
output. Without discussing, why XML based etc. , I think it might be
useful for some people. I compared it with some of the python engines
and I think it fares allright. Based on this (non comprehensive) test,
I got the following results on my machine:
[x@y templates] python 
Genshi tag builder                            488.18 ms
Genshi template                               298.26 ms
Genshi template + tag builder                 528.03 ms
Mako Template                                  55.21 ms
Cheetah template                               60.09 ms
StringIO                                       61.13 ms
cStringIO                                      10.22 ms
list concat                                     7.51 ms

with the following little test on Parclate:
--------------- code
local t_insert,s_format,Parclate=table.insert,string.format
local socket,Parclate=require('socket'),require('Parclate')
local templ=[=[
    <tr l:for="_,row  in pairs(tab)">
    <td l:for="_,cell in pairs(row)">${cell}</td>

local function run(n)
	-- parse and compile the template
	local ct=Parclate(templ):compile()
	local tab={}
	for i=1,1000 do
		t_insert(tab, {a=1,b=2,c=3,d=4,e=5,f=6,g=7,h=8,i=9,j=10})
	local s=socket.gettime()
	for i=1,n do local r=tostring(ct) end
	local e=socket.gettime()
	print(s_format('parclate:\t%.3f ms',(e-s)/n*1000))

----------------end of code

I got this:
[x@y templates] lua test.lua 
parclate:	25.366 ms

So, I think it's doing allright. I understand speed is not everything,
but I do think it's fairly useable as well. Atm, the codebase is still
intermingled with the http server but I have best intentions to get it
out of there.:
Docs(more of a description):
Test(More of a showcase):

comments, improvements and ideas welcome