Based on some off-list suggestions, and some hunches, I added a few more tests. It has been expanded a little more to include HTML::Template, HTML::Template::Pro, and TT, and versions that read from file and ones that use a scalar variable to hold template data (to remove the file read from the equation).
I think that covers a pretty wide range of options, and I'm done tweaking the tests. If anyone wants to see any others added, feel free to send me a patch, and I'll update it. Benchmark: timing 40 iterations of HT1loop_cachedtmpl, HT1loop_fromfile, HT2loops_cachedtmpl, HT2loops_fromfile, HTPro1loop_cachedtmpl, HTPro1loop_fromfile, HTPro2loops_cachedtmpl, HTPro2loops_fromfile, Templateloop_cachedtmpl, Templateloop_fromfile, perl... HT1loop_cachedtmpl: 12 wallclock secs (11.72 usr + 0.05 sys = 11.77 CPU) @ 3.40/s (n=40) HT1loop_fromfile: 12 wallclock secs (11.74 usr + 0.06 sys = 11.80 CPU) @ 3.39/s (n=40) HT2loops_cachedtmpl: 40 wallclock secs (39.82 usr + 0.06 sys = 39.88 CPU) @ 1.00/s (n=40) HT2loops_fromfile: 40 wallclock secs (39.79 usr + 0.08 sys = 39.87 CPU) @ 1.00/s (n=40) HTPro1loop_cachedtmpl: 5 wallclock secs ( 4.40 usr + 0.46 sys = 4.86 CPU) @ 8.23/s (n=40) HTPro1loop_fromfile: 5 wallclock secs ( 4.42 usr + 0.50 sys = 4.92 CPU) @ 8.13/s (n=40) HTPro2loops_cachedtmpl: 10 wallclock secs ( 9.55 usr + 0.73 sys = 10.28 CPU) @ 3.89/s (n=40) HTPro2loops_fromfile: 11 wallclock secs ( 9.74 usr + 0.76 sys = 10.50 CPU) @ 3.81/s (n=40) Templateloop_cachedtmpl: 16 wallclock secs (16.38 usr + 0.16 sys = 16.54 CPU) @ 2.42/s (n=40) Templateloop_fromfile: 19 wallclock secs (17.45 usr + 0.98 sys = 18.43 CPU) @ 2.17/s (n=40) perl: 0 wallclock secs ( 0.68 usr + 0.01 sys = 0.69 CPU) @ 57.97/s (n=40) -- Josh I. On Thu, May 15, 2008 at 7:59 PM, Joshua Miller <[EMAIL PROTECTED]> wrote: > FWIW, I updated the benchmarks to include that one. While not as slow as > the nested loops in HTML::Template, it slower than the single loop in > HTML::Template. > > http://moc.rellimhsoj.com/perl/tmplloop_benchmark/ > > Benchmark: timing 40 iterations of Templateloop, perl, tmpl1loop, > tmpl2loops... > Templateloop: 18 wallclock secs (17.10 usr + 0.95 sys = 18.05 CPU) @ 2.22/s > (n=40) > perl: 0 wallclock secs ( 0.68 usr + 0.00 sys = 0.68 CPU) @ 58.82/s > (n=40) > > (warning: too few iterations for a reliable count) > tmpl1loop: 12 wallclock secs (11.78 usr + 0.06 sys = 11.84 CPU) @ 3.38/s > (n=40) > tmpl2loops: 41 wallclock secs (40.41 usr + 0.08 sys = 40.49 CPU) @ 0.99/s > (n=40) > > Any other examples to throw in here? > -- > Josh I. > > > On Thu, May 15, 2008 at 7:40 PM, Cees Hek <[EMAIL PROTECTED]> wrote: > >> On Fri, May 16, 2008 at 2:03 AM, Stephen Carville >> <[EMAIL PROTECTED]> wrote: >> > Is there any way to have a template where the number of columns is >> > determined at run time? I know how to use TMPL_LOOP but that only >> > lets me vary the number of rows. >> >> I realize that you are using HTML::Template, and you may be tied to it >> for reasons good or bad, but >> whenever I see people trying to bend a tool to do things against it's >> will I feel obliged to show another way ;) >> >> In my example below, the data is provided in a format that is easy to >> generate using a DBI call, and the template itself is pretty straight >> forward. Row colouring is also made easy using the Cycle plugin (if >> you want to alternate between three colours, just add another entry >> into the cycle and leave the rest of the template as is). >> >> use Template; >> >> my $template = Template->new( POST_CHOMP => 1 ); >> my $data = { >> headers => [qw(col1 col2 col3 col4)], >> rows => [ >> [ qw(1.1 1.2 1.3 1.4) ], >> [ qw(2.1 2.2 2.3 2.4) ], >> [ qw(3.1 3.2 3.3 3.4) ], >> [ qw(4.1 4.2 4.3 4.4) ], >> [ qw(5.1 5.2 5.3 5.4) ], >> [ qw(6.1 6.2 6.3 6.4) ], >> ], >> }; >> $template->process(\*DATA, $data) or die $template->error; >> __END__ >> [% USE rowclass = Cycle('oddclass', 'evenclass') %] >> <table> >> <tr> >> [% FOREACH col IN headers %] >> <th>[% col %]</th> >> [% END %] >> </tr> >> [% FOREACH row IN rows %] >> <tr class="[% rowclass %]"> >> [% FOREACH col IN row %] >> <td>[% col %]</td> >> [% END %] >> </tr> >> [% END %] >> </table> >> >> >> Cheers, >> >> Cees >> >> ##### CGI::Application community mailing list ################ >> ## ## >> ## To unsubscribe, or change your message delivery options, ## >> ## visit: http://www.erlbaum.net/mailman/listinfo/cgiapp ## >> ## ## >> ## Web archive: http://www.erlbaum.net/pipermail/cgiapp/ ## >> ## Wiki: http://cgiapp.erlbaum.net/ ## >> ## ## >> ################################################################ >> >> > ##### CGI::Application community mailing list ################ ## ## ## To unsubscribe, or change your message delivery options, ## ## visit: http://www.erlbaum.net/mailman/listinfo/cgiapp ## ## ## ## Web archive: http://www.erlbaum.net/pipermail/cgiapp/ ## ## Wiki: http://cgiapp.erlbaum.net/ ## ## ## ################################################################