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