lua-users home
lua-l archive

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


Hi,

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,
http://code.google.com/p/spitfire/source/browse/trunk/tests/perf/bigtable.py
I got the following results on my machine:
[x@y templates] python bigtable.py 
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=[=[
	<table>
    <tr l:for="_,row  in pairs(tab)">
    <td l:for="_,cell in pairs(row)">${cell}</td>
    </tr>
    </table>
]=]

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})
	end
	ct.tab=tab
	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

run(100)
----------------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.:
Code:
http://github.com/tobbik/parcle/blob/master/lib/Parclate.lua
Docs(more of a description):
http://github.com/tobbik/parcle/blob/master/doc/Parclate.rst
Test(More of a showcase):
http://github.com/tobbik/parcle/blob/master/tests/parclate.lua

comments, improvements and ideas welcome

Thanks,
	-T