NAME

WE_Frontend::Plugin::Benchmark - TT plugin for making benchmarks

SYNOPSIS

[% USE b = Benchmark %]
...
[% b.stop(tag) %]

DESCRIPTION

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.

ALTERNATIVES

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;

AUTHOR

Slaven Rezic <slaven@rezic.de>

COPYRIGHT

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.

SEE ALSO

Time::HiRes.