DTL-Fast

 view release on metacpan or  search on metacpan

lib/DTL/Fast.pod  view on Meta::CPAN


=head1 BENCHMARKS

I've compared module speed with previous abandoned implementation: L<C<Dotiac::DTL>> in both modes: FCGI and CGI. Test template and scripts are in /timethese directory.
Django templating in Python with cache works about 80% slower than C<DTL::Fast>.

=head2 FCGI/mod_perl

Template parsing permormance with software cache wiping on each iteration:

    Benchmark: timing 5000 iterations of DTL::Fast  , Dotiac::DTL...

    DTL::Fast  :  5 wallclock secs ( 4.59 usr +  0.12 sys =  4.71 CPU) @ 1061.36/s (n=5000)
    Dotiac::DTL: 41 wallclock secs (38.66 usr +  2.22 sys = 40.88 CPU) @ 122.30/s (n=5000)

C<DTL::Fast> parsing templates 8.67 times faster, than L<C<Dotiac::DTL>>.

To run this test, you need to alter L<C<Dotiac::DTL>> module and change declaration of C<my %cache;> to C<our %cache;>.

Rendering of pre-compiled template (software cache):

    Benchmark: timing 3000 iterations of DTL::Fast  , Dotiac::DTL...

    DTL::Fast  : 34 wallclock secs (33.86 usr +  0.39 sys = 34.25 CPU) @ 87.59/s (n=3000)
    Dotiac::DTL: 53 wallclock secs (52.93 usr +  0.62 sys = 53.55 CPU) @ 56.02/s (n=3000)

Tests shows, that C<DTL::Fast> works a 56% faster, than L<C<Dotiac::DTL>> in persistent environment.

=head2 CGI

This test rendered test template many times by external script, invoked via C<system> call:

    Benchmark: timing 300 iterations of Dotiac render     , Fast cached render, Fast render

    DTL::Fast  : 40 wallclock secs ( 0.00 usr  0.12 sys + 35.14 cusr  4.98 csys = 40.24 CPU) @  7.45/s (n=300)
    Dotiac::DTL: 51 wallclock secs ( 0.00 usr  0.12 sys + 38.29 cusr 12.63 csys = 51.04 CPU) @  5.88/s (n=300)

Tests shows, that C<DTL::Fast> works 27% faster, than L<C<Dotiac::DTL>> in CGI environment.

=head2 DTL::Fast steps performance

    1 Cache key  :  0 wallclock secs ( 0.19 usr +  0.00 sys =  0.19 CPU) @ 534759.36/s (n=100000)
    2 Decompress :  0 wallclock secs ( 0.27 usr +  0.00 sys =  0.27 CPU) @ 377358.49/s (n=100000)

t/tag/for.t  view on Meta::CPAN

This is a value2-3-2
Still value10-value11-value12
This is a value20-value21-value22
This is a value0-1-3
This is a value1-2-3
This is a value2-3-3
Still value20-value21-value22

_EOT_

is( DTL::Fast::Template->new($template, 'dirs' => $dirs)->render($context), $test_string, 'Nested iterations');

$template = <<'_EOT_';
{% for a,b ,c in empty_array %}This is a {{ a }}-{{ b }}-{{ c }}
{% empty %}Nothing in this array
{% endfor %}
_EOT_

$test_string = <<'_EOT_';
Nothing in this array

timetheese/performance.pl  view on Meta::CPAN

}

sub dtl_parse
{
    $tpl = get_template( 
        @params, 
        'no_cache' => 1,
    );
}

print "This is a test for optimisation iterations\n";

timethese( 100000, {
    '1 Cache key  ' => \&dtl_cache_key,
    '2 Decompress ' => \&dtl_decompress,
    '3 Serialize  ' => \&dtl_serialize,
    '4 Deserialize' => \&dtl_deserialize,
    '5 Compress   ' => \&dtl_compress,
    '6 Validate   ' => \&dtl_validate,
});



( run in 2.895 seconds using v1.01-cache-2.11-cpan-71847e10f99 )