« lib/Template/Benchmark/Engines/TextTemplate.pm
↑ Summary
lib/Template/Benchmark/Engines/TextTemplet.pm »
| 1 | package Template::Benchmark::Engines::TextTemplateSimple; | ||
| 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::Template::Simple; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 9 | |||
| 10 | our $VERSION = '1.09_01'; | ||
| 11 | |||
| 12 | our %feature_syntaxes = ( | ||
| 13 | literal_text => | ||
| 14 | join( "\n", ( join( ' ', ( 'foo' ) x 12 ) ) x 5 ), | ||
| 15 | scalar_variable => | ||
| 16 | '<%= $p{scalar_variable} %>', | ||
| 17 | hash_variable_value => | ||
| 18 | '<%= $p{hash_variable}{hash_value_key} %>', | ||
| 19 | array_variable_value => | ||
| 20 | '<%= $p{array_variable}[ 2 ] %>', | ||
| 21 | deep_data_structure_value => | ||
| 22 | '<%= $p{this}{is}{a}{very}{deep}{hash}{structure} %>', | ||
| 23 | array_loop_value => | ||
| 24 | '<% foreach ( @{$p{array_loop}} ) { %><%= $_ %><% } %>', | ||
| 25 | hash_loop_value => | ||
| 26 | '<% foreach ( sort( keys( %{$p{hash_loop}} ) ) ) { %>' . | ||
| 27 | '<%= $_ %>: <%= $p{hash_loop}{$_} %>' . | ||
| 28 | '<% } %>', | ||
| 29 | records_loop_value => | ||
| 30 | '<% foreach ( @{$p{records_loop}} ) { %>' . | ||
| 31 | '<%= $_->{name} %>: <%= $_->{age} %>' . | ||
| 32 | '<% } %>', | ||
| 33 | array_loop_template => | ||
| 34 | '<% foreach ( @{$p{array_loop}} ) { %><%= $_ %><% } %>', | ||
| 35 | hash_loop_template => | ||
| 36 | '<% foreach ( sort( keys( %{$p{hash_loop}} ) ) ) { %>' . | ||
| 37 | '<%= $_ %>: <%= $p{hash_loop}{$_} %>' . | ||
| 38 | '<% } %>', | ||
| 39 | records_loop_template => | ||
| 40 | '<% foreach ( @{$p{records_loop}} ) { %>' . | ||
| 41 | '<%= $_->{name} %>: <%= $_->{age} %>' . | ||
| 42 | '<% } %>', | ||
| 43 | constant_if_literal => | ||
| 44 | '<% if( 1 ) { %>true<% } %>', | ||
| 45 | variable_if_literal => | ||
| 46 | '<% if( $p{variable_if} ) { %>true<% } %>', | ||
| 47 | constant_if_else_literal => | ||
| 48 | '<% if( 1 ) { %>true<% } else { %>false<% } %>', | ||
| 49 | variable_if_else_literal => | ||
| 50 | '<% if( $p{variable_if_else} ) { %>true<% } else { %>' . | ||
| 51 | 'false<% } %>', | ||
| 52 | constant_if_template => | ||
| 53 | '<% if( 1 ) { %><%= $p{template_if_true} %><% } %>', | ||
| 54 | variable_if_template => | ||
| 55 | '<% if( $p{variable_if} ) { %><%= $p{template_if_true} %>' . | ||
| 56 | '<% } %>', | ||
| 57 | constant_if_else_template => | ||
| 58 | '<% if( 1 ) { %><%= $p{template_if_true} %><% } else { %>' . | ||
| 59 | '<%= $p{template_if_false} %><% } %>', | ||
| 60 | variable_if_else_template => | ||
| 61 | '<% if( $p{variable_if_else} ) { %>' . | ||
| 62 | '<%= $p{template_if_true} %><% } else { %>' . | ||
| 63 | '<%= $p{template_if_false} %><% } %>', | ||
| 64 | constant_expression => | ||
| 65 | '<%= 10 + 12 %>', | ||
| 66 | variable_expression => | ||
| 67 | '<%= $p{variable_expression_a} * ' . | ||
| 68 | '$p{variable_expression_b} %>', | ||
| 69 | complex_variable_expression => | ||
| 70 | '<%= ( ( $p{variable_expression_a} * ' . | ||
| 71 | '$p{variable_expression_b} ) + ' . | ||
| 72 | '$p{variable_expression_a} - ' . | ||
| 73 | '$p{variable_expression_b} ) / ' . | ||
| 74 | '$p{variable_expression_b} %>', | ||
| 75 | constant_function => | ||
| 76 | q{<%= substr( 'this has a substring.', 11, 9 ) %>}, | ||
| 77 | variable_function => | ||
| 78 | '<%= substr( $p{variable_function_arg}, 4, 2 ) %>', | ||
| 79 | ); | ||
| 80 | |||
| 81 | sub syntax_type { return( 'embedded-perl' ); } | ||
| 82 | sub pure_perl { return( 1 ); } | ||
| 83 | |||
| 84 | sub benchmark_descriptions | ||
| 85 | { | ||
| 86 | return( { | ||
| 87 | TeTeSimp => | ||
| 88 | "Text::Template::Simple ($Text::Template::Simple::VERSION)", | ||
| 89 | } ); | ||
| 90 | } | ||
| 91 | |||
| 92 | sub benchmark_functions_for_uncached_string | ||
| 93 | { | ||
| 94 | my ( $self ) = @_; | ||
| 95 | |||
| 96 | return( { | ||
| 97 | TeTeSimp => | ||
| 98 | sub | ||
| 99 | { | ||
| 100 | my $t = Text::Template::Simple->new( | ||
| 101 | header => 'my %p = @_;', | ||
| 102 | ); | ||
| 103 | \$t->compile( [ STRING => $_[ 0 ] ], | ||
| 104 | [ %{$_[ 1 ]}, %{$_[ 2 ]} ] ); | ||
| 105 | }, | ||
| 106 | } ); | ||
| 107 | } | ||
| 108 | |||
| 109 | sub benchmark_functions_for_uncached_disk | ||
| 110 | { | ||
| 111 | my ( $self, $template_dir ) = @_; | ||
| 112 | my ( @template_dirs ); | ||
| 113 | |||
| 114 | @template_dirs = ( $template_dir ); | ||
| 115 | |||
| 116 | return( { | ||
| 117 | TeTeSimp => | ||
| 118 | sub | ||
| 119 | { | ||
| 120 | my $t = Text::Template::Simple->new( | ||
| 121 | header => 'my %p = @_;', | ||
| 122 | include_paths => \@template_dirs, | ||
| 123 | ); | ||
| 124 | \$t->compile( [ FILE => $_[ 0 ] ], | ||
| 125 | [ %{$_[ 1 ]}, %{$_[ 2 ]} ] ); | ||
| 126 | }, | ||
| 127 | } ); | ||
| 128 | } | ||
| 129 | |||
| 130 | sub benchmark_functions_for_disk_cache | ||
| 131 | { | ||
| 132 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 133 | my ( @template_dirs ); | ||
| 134 | |||
| 135 | @template_dirs = ( $template_dir ); | ||
| 136 | |||
| 137 | return( { | ||
| 138 | TeTeSimp => | ||
| 139 | sub | ||
| 140 | { | ||
| 141 | my $t = Text::Template::Simple->new( | ||
| 142 | header => 'my %p = @_;', | ||
| 143 | include_paths => \@template_dirs, | ||
| 144 | cache => 1, | ||
| 145 | cache_dir => $cache_dir, | ||
| 146 | ); | ||
| 147 | \$t->compile( [ FILE => $_[ 0 ] ], | ||
| 148 | [ %{$_[ 1 ]}, %{$_[ 2 ]} ] ); | ||
| 149 | }, | ||
| 150 | } ); | ||
| 151 | } | ||
| 152 | |||
| 153 | sub benchmark_functions_for_shared_memory_cache | ||
| 154 | { | ||
| 155 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 156 | |||
| 157 | return( undef ); | ||
| 158 | } | ||
| 159 | |||
| 160 | sub benchmark_functions_for_memory_cache | ||
| 161 | { | ||
| 162 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 163 | my ( @template_dirs ); | ||
| 164 | |||
| 165 | @template_dirs = ( $template_dir ); | ||
| 166 | |||
| 167 | return( { | ||
| 168 | TeTeSimp => | ||
| 169 | sub | ||
| 170 | { | ||
| 171 | my $t = Text::Template::Simple->new( | ||
| 172 | header => 'my %p = @_;', | ||
| 173 | include_paths => \@template_dirs, | ||
| 174 | cache => 1, | ||
| 175 | ); | ||
| 176 | \$t->compile( [ FILE => $_[ 0 ] ], | ||
| 177 | [ %{$_[ 1 ]}, %{$_[ 2 ]} ] ); | ||
| 178 | }, | ||
| 179 | } ); | ||
| 180 | } | ||
| 181 | |||
| 182 | sub benchmark_functions_for_instance_reuse | ||
| 183 | { | ||
| 184 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 185 | |||
| 186 | return( undef ); | ||
| 187 | } | ||
| 188 | |||
| 189 | 1; | ||
| 190 | |||
| 191 | __END__ | ||