On Thu, 15 Nov 2001, Perrin Harkins wrote:
>
> Using $r might be an efficiency gain. I'd suggest benchamrking if anyone is
> really curious.
Hmm, well, I'm not very experienced in benchmarking, but I had a go at it,
and here's what I got. Hopefully I'm not cocking anything up too badly. It
appears that there isn't much difference between using and not using the
Apache request object as the third argument to the process() call
(although, as expected, the method suggested in the TT2 docs,
i.e. creating the Template object inside the handler, and setting the
value of the OUTPUT config param to $r, is out of
the ballpark).
- nick
-------------------------
nick@world ~/tmp/ttt>./test && cat test && cat test.html && cat test.tmpl
&& cat MyTest1.pm && cat MyTest2.pm && cat MyTest3.pm
Benchmark: timing 10000 iterations of inside_handler, with_OUTPUT,
without_OUTPUT...
inside_handler: 33 wallclock secs (32.83 usr + 0.20 sys = 33.03 CPU)
with_OUTPUT: 7 wallclock secs ( 6.53 usr + 0.05 sys = 6.58 CPU)
without_OUTPUT: 7 wallclock secs ( 6.55 usr + 0.02 sys = 6.57 CPU)
## test
#!/usr/bin/perl -w
use strict;
use Benchmark;
use Apache::FakeRequest;
use MyTest1;
use MyTest2;
use MyTest3;
my $r = Apache::FakeRequest->new('get_remote_host'=>'foobar.com');
timethese(10000, { without_OUTPUT => \&without_OUTPUT,
with_OUTPUT => \&with_OUTPUT,
inside_handler => \&inside_handler, });
sub without_OUTPUT { MyTest1::handler($r); }
sub with_OUTPUT { MyTest2::handler($r); }
sub inside_handler { MyTest3::handler($r); }
## test.html
[%
INCLUDE test.tmpl
NAME = 'world'
% ]
## test.tmpl
<HTML>
<HEAD>
<TITLE>
hello, world
</TITLE>
</HEAD>
<BODY>
Hello, [% name %]
</BODY>
</HTML>
## MyTest1.pm
package MyTest1;
use strict;
use Template;
my $t = Template->new();
sub handler {
my $r = shift;
$t->process('./test.html', {foo => 'bar'});
return 200;
}
1;
## MyTest2.pm
package MyTest2;
use strict;
use Template;
my $t = Template->new();
sub handler {
my $r = shift;
$t->process('./test.html', {foo => 'bar'}, $r);
return 200;
}
1;
## MyTest3.pm
package MyTest3;
use strict;
use Template;
sub handler {
my $r = shift;
my $t = Template->new(OUTPUT => $r);
$t->process('./test.html', {foo => 'bar'});
return 200;
}
1;