« lib/Template/Benchmark/Engines/TextXslate.pm
↑ Summary
lib/Template/Benchmark/Engines/MojoTemplate.pm »
| 1 | package Template::Benchmark::Engines::TextXslateTT; | ||
| 2 | |||
| 3 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 1 | ▶ | use base qw/Template::Benchmark::Engine/; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 0 | ▶ | use Text::Xslate 0.1053; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 9 | use Text::Xslate::Bridge::TT2 1.0002; | ||
| 10 | |||
| 11 | our $VERSION = '1.09_01'; | ||
| 12 | |||
| 13 | our %feature_syntaxes = ( | ||
| 14 | literal_text => | ||
| 15 | join( "\n", ( join( ' ', ( 'foo' ) x 12 ) ) x 5 ), | ||
| 16 | scalar_variable => | ||
| 17 | '[% scalar_variable %]', | ||
| 18 | hash_variable_value => | ||
| 19 | '[% hash_variable.hash_value_key %]', | ||
| 20 | array_variable_value => | ||
| 21 | '[% array_variable.2 %]', | ||
| 22 | deep_data_structure_value => | ||
| 23 | '[% this.is.a.very.deep.hash.structure %]', | ||
| 24 | array_loop_value => | ||
| 25 | '[% FOREACH i IN array_loop %][% i %][% END %]', | ||
| 26 | hash_loop_value => | ||
| 27 | undef, | ||
| 28 | # '[% FOREACH k IN hash_loop %][% k.key %]: ' . | ||
| 29 | # '[% k.value %][% END %]', | ||
| 30 | records_loop_value => | ||
| 31 | '[% FOREACH r IN records_loop %][% r.name %]: ' . | ||
| 32 | '[% r.age %][% END %]', | ||
| 33 | array_loop_template => | ||
| 34 | '[% FOREACH i IN array_loop %][% i %][% END %]', | ||
| 35 | hash_loop_template => | ||
| 36 | undef, | ||
| 37 | # '[% FOREACH k IN hash_loop %][% k.key %]: ' . | ||
| 38 | # '[% k.value %][% END %]', | ||
| 39 | records_loop_template => | ||
| 40 | '[% FOREACH r IN records_loop %][% r.name %]: ' . | ||
| 41 | '[% r.age %][% END %]', | ||
| 42 | constant_if_literal => | ||
| 43 | '[% IF 1 %]true[% END %]', | ||
| 44 | variable_if_literal => | ||
| 45 | '[% IF variable_if %]true[% END %]', | ||
| 46 | constant_if_else_literal => | ||
| 47 | '[% IF 1 %]true[% ELSE %]false[% END %]', | ||
| 48 | variable_if_else_literal => | ||
| 49 | '[% IF variable_if_else %]true[% ELSE %]false[% END %]', | ||
| 50 | constant_if_template => | ||
| 51 | '[% IF 1 %][% template_if_true %][% END %]', | ||
| 52 | variable_if_template => | ||
| 53 | '[% IF variable_if %][% template_if_true %][% END %]', | ||
| 54 | constant_if_else_template => | ||
| 55 | '[% IF 1 %][% template_if_true %][% ELSE %]' . | ||
| 56 | '[% template_if_false %][% END %]', | ||
| 57 | variable_if_else_template => | ||
| 58 | '[% IF variable_if_else %][% template_if_true %][% ELSE %]' . | ||
| 59 | '[% template_if_false %][% END %]', | ||
| 60 | constant_expression => | ||
| 61 | '[% 10 + 12 %]', | ||
| 62 | variable_expression => | ||
| 63 | '[% variable_expression_a * variable_expression_b %]', | ||
| 64 | complex_variable_expression => | ||
| 65 | '[% ( ( variable_expression_a * variable_expression_b ) + ' . | ||
| 66 | 'variable_expression_a - variable_expression_b ) / ' . | ||
| 67 | 'variable_expression_b %]', | ||
| 68 | constant_function => | ||
| 69 | q{[% 'this has a substring.'.substr( 11, 9 ) %]}, | ||
| 70 | # undef, | ||
| 71 | variable_function => | ||
| 72 | '[% variable_function_arg.substr( 4, 2 ) %]', | ||
| 73 | ); | ||
| 74 | |||
| 75 | sub syntax_type { return( 'mini-language' ); } | ||
| 76 | sub pure_perl | ||
| 77 | { | ||
| 78 | return( 1 ) if $ENV{ XSLATE } and $ENV{ XSLATE } =~ / \b pp \b /xms; | ||
| 79 | return( 0 ); | ||
| 80 | } | ||
| 81 | |||
| 82 | sub benchmark_descriptions | ||
| 83 | { | ||
| 84 | if( __PACKAGE__->pure_perl() ) | ||
| 85 | { | ||
| 86 | return( { | ||
| 87 | TeXsTTPP => | ||
| 88 | "Text::Xslate::PP ($Text::Xslate::PP::VERSION) " . | ||
| 89 | "in Template::Toolkit mode", | ||
| 90 | } ); | ||
| 91 | } | ||
| 92 | return( { | ||
| 93 | TeXsTT => | ||
| 94 | "Text::Xslate ($Text::Xslate::VERSION) " . | ||
| 95 | "in Template::Toolkit mode", | ||
| 96 | } ); | ||
| 97 | } | ||
| 98 | |||
| 99 | sub benchmark_functions_for_uncached_string | ||
| 100 | { | ||
| 101 | my ( $self ) = @_; | ||
| 102 | |||
| 103 | return( { | ||
| 104 | ( __PACKAGE__->pure_perl() ? 'TeXsTTPP' : 'TeXsTT' ) => | ||
| 105 | sub | ||
| 106 | { | ||
| 107 | my $t = Text::Xslate->new( | ||
| 108 | syntax => 'TTerse', | ||
| 109 | module => [ qw/Text::Xslate::Bridge::TT2/ ], | ||
| 110 | cache => 0, | ||
| 111 | ); | ||
| 112 | \$t->render_string( $_[ 0 ], { %{$_[ 1 ]}, %{$_[ 2 ]} } ); | ||
| 113 | }, | ||
| 114 | } ); | ||
| 115 | } | ||
| 116 | |||
| 117 | sub benchmark_functions_for_uncached_disk | ||
| 118 | { | ||
| 119 | my ( $self, $template_dir ) = @_; | ||
| 120 | my ( @template_dirs ); | ||
| 121 | |||
| 122 | @template_dirs = ( $template_dir ); | ||
| 123 | |||
| 124 | return( { | ||
| 125 | ( __PACKAGE__->pure_perl() ? 'TeXsTTPP' : 'TeXsTT' ) => | ||
| 126 | sub | ||
| 127 | { | ||
| 128 | my $t = Text::Xslate->new( | ||
| 129 | syntax => 'TTerse', | ||
| 130 | module => [ qw/Text::Xslate::Bridge::TT2/ ], | ||
| 131 | path => \@template_dirs, | ||
| 132 | cache => 0, | ||
| 133 | ); | ||
| 134 | \$t->render( $_[ 0 ], { %{$_[ 1 ]}, %{$_[ 2 ]} } ); | ||
| 135 | }, | ||
| 136 | } ); | ||
| 137 | } | ||
| 138 | |||
| 139 | sub benchmark_functions_for_disk_cache | ||
| 140 | { | ||
| 141 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 142 | my ( @template_dirs ); | ||
| 143 | |||
| 144 | @template_dirs = ( $template_dir ); | ||
| 145 | |||
| 146 | return( { | ||
| 147 | ( __PACKAGE__->pure_perl() ? 'TeXsTTPP' : 'TeXsTT' ) => | ||
| 148 | sub | ||
| 149 | { | ||
| 150 | my $t = Text::Xslate->new( | ||
| 151 | syntax => 'TTerse', | ||
| 152 | module => [ qw/Text::Xslate::Bridge::TT2/ ], | ||
| 153 | path => \@template_dirs, | ||
| 154 | cache_dir => $cache_dir, | ||
| 155 | cache => 2, | ||
| 156 | ); | ||
| 157 | \$t->render( $_[ 0 ], { %{$_[ 1 ]}, %{$_[ 2 ]} } ); | ||
| 158 | }, | ||
| 159 | } ); | ||
| 160 | } | ||
| 161 | |||
| 162 | sub benchmark_functions_for_shared_memory_cache | ||
| 163 | { | ||
| 164 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 165 | |||
| 166 | return( undef ); | ||
| 167 | } | ||
| 168 | |||
| 169 | sub benchmark_functions_for_memory_cache | ||
| 170 | { | ||
| 171 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 172 | |||
| 173 | return( undef ); | ||
| 174 | } | ||
| 175 | |||
| 176 | sub benchmark_functions_for_instance_reuse | ||
| 177 | { | ||
| 178 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 179 | my ( @template_dirs, $t ); | ||
| 180 | |||
| 181 | @template_dirs = ( $template_dir ); | ||
| 182 | |||
| 183 | return( { | ||
| 184 | ( __PACKAGE__->pure_perl() ? 'TeXsTTPP' : 'TeXsTT' ) => | ||
| 185 | sub | ||
| 186 | { | ||
| 187 | $t = Text::Xslate->new( | ||
| 188 | syntax => 'TTerse', | ||
| 189 | module => [ qw/Text::Xslate::Bridge::TT2/ ], | ||
| 190 | path => \@template_dirs, | ||
| 191 | cache_dir => $cache_dir, | ||
| 192 | cache => 2, | ||
| 193 | ) unless $t; | ||
| 194 | \$t->render( $_[ 0 ], { %{$_[ 1 ]}, %{$_[ 2 ]} } ); | ||
| 195 | }, | ||
| 196 | } ); | ||
| 197 | } | ||
| 198 | |||
| 199 | 1; | ||
| 200 | |||
| 201 | __END__ | ||