in reply to I need to template this
There are a lot of good reasons to use H::T over TT:
Now, TT is more featureful and has its own UI-compatible friends, like Jemplate. It all depends on what your needs are.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: I need to template this
by Rhandom (Curate) on Apr 19, 2007 at 21:10 UTC | |
TT is too heavy for what you wantSorry - this is long... I hear the "too heavy" argument a lot as a reason to not use TT. I've provided a test script below with benchmarks that show relative speed for a highly contrived template. If TT is used in a mod_perl environment - it is faster than HT. In a non-mod_perl environment (or also in a mod_perl environment you could always use CGI::Ex::Template and then you have the full features of TT with the "lightness" of HTML::Template. The other reason I hear is because they don't want to give too much ability to the HTML designers or because they don't want to have business logic in the templates. The first point seems roughly equivalent to SysAdmins on my network telling me I have to use Lua because they don't want me to have too many features in my programming. On the second point - there is almost nothing you can do to prevent your designers from controlling business logic from the HTML -- Javascript provides all the rope they need to hang themselves. The only option here is to ask them not to do that. So if all the points for using H::T are really veiled non-issues - then the only real reason to pick H::T over TT or likewise to pick TT over H::T is one of religion and is generally based on what system the developer started with in the first place. Well - anyway - the following is a script that tests the templates under different operational modes - passing in a string containing the template, passing in a file containing the template, and caching the template in memory, or the compiled template on the file system (isn't it funny that they all have essentially the same feature sets but have diffent APIs and syntax). This file is included with the CGI::Ex suite under the samples/benchmark directory. Unfortunately the copy of this file on cpan is out of date - but will include this updated file in the next release. Read more... (12 kB)
That script output the output below on my machine (I've removed some of the timethese output to shorten what is presented). Remember that the template is used for the test is trivially short - but it does give a good approximation of "heavy" vs "light". The following abreviations are used:
So using Template Toolkit with the XS stash in a mod_perl environment would offer the best performance (not counting CGI::Ex::Template in a cached environment). I do agree that using TT in a CGI environment without any caching may be a bit heavy (I use CGI::Ex::Template in those cases). This has been a long answer to a short comment about TT being too heavy. Apache is heavy too - but it gets the job done. Personally I use whatever templating system the previous coder used when I go in and maintain code. But on all new work I use CGI::Ex::Template because it gives me the power of TT, but is even faster and lighter.
my @a=qw(random brilliant braindead); print $a[rand(@a)];
| [reply] [d/l] [select] |
by samtregar (Abbot) on Apr 20, 2007 at 16:46 UTC | |
-sam | [reply] |
by Rhandom (Curate) on Apr 21, 2007 at 01:31 UTC | |
I really think that the way to go is to have all of the various template languages compile to an opcode tree - a common opcode tree - and then make a common runtime engine that is blazingly fast - for all of them. Maybe once parrot and perl6 are done we can just compile the templates to parrot bytecode with optional JIT (if that ever becomes mainstream). Really though - I don't know of anybody using H::T - but I know lots of people using H::T::Expr. There wouldn't happen to be a H::T::Expr::JIT would there. I don't think so as there isn't even a file_cache version of H::T::Expr. I think the H::T::JIT must be a pretty dandy piece of work. I will add it to the tests - I'm curious now.
my @a=qw(random brilliant braindead); print $a[rand(@a)];
| [reply] |
by Rhandom (Curate) on Apr 21, 2007 at 04:29 UTC | |
|
Re^2: I need to template this
by polettix (Vicar) on Apr 20, 2007 at 13:02 UTC | |
Flavio | [reply] |