WE_Frontend::Plugin::Benchmark - TT plugin for making benchmarks
[% USE b = Benchmark %] ... [% b.stop(tag) %]
This plugin may be used to benchmark a code block in a TT template. The start of the benchmarked block should be marked with:
[% USE b = Benchmark %]
and the end with
[% b.stop(tag) %]
The (real, not CPU) run time is written to STDERR. tag is an arbitrary string which may be used to identify a benchmarked block.
On CPAN, the module Template::Timer exists.
This module is based on the following suggestion by Gavin Estey (see the TT mailing list):
You can use a Template::Context subclass to insert timing comments in the HTML.
Just overried what class is used:
$Template::Config::CONTEXT = 'TimingContext'; package TimingContext; use base qw( Template::Context ); use Time::HiRes qw( gettimeofday tv_interval ); foreach my $sub (qw( process include )) { my $super = __PACKAGE__->can("SUPER::$sub") or die; *$sub = sub { my $self = shift; my $template = ref $_[0] ? $_[0]->name : $_[0]; my $start = [gettimeofday]; my $data = $super->($self, @_); my $elapsed = tv_interval($start); return "<!-- START: $template -->\n$data\n<!-- END: $template ($elapsed seconds) -->"; }; } 1;
Slaven Rezic <slaven@rezic.de>
Copyright (c) 2002 Slaven Rezic. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Time::HiRes.
To install WE::DB, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WE::DB
CPAN shell
perl -MCPAN -e shell install WE::DB
For more information on module installation, please visit the detailed CPAN module installation guide.