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