8 use Template::Teeny::Stash;
11 my $iter = shift || -2 ;
13 use Benchmark qw(:hireswallclock cmpthese);
16 my $ts = Template::Simple->new() ;
17 $ts->add_templates( { bench => 'hehe [% name %]' } ) ;
19 my $tsc = Template::Simple->new() ;
20 $tsc->add_templates( { bench => 'hehe [% name %]' } ) ;
21 $tsc->compile( 'bench' ) ;
23 my $tt = Template::Teeny->new({ include_path => ['t/tpl'] });
24 my $stash = Template::Teeny::Stash->new({ name => 'bob' });
26 my $t = Template->new({ INCLUDE_PATH => 't/tpl', COMPILE_EXT => '.tc' });
28 open my $fh, '>/dev/null';
30 $tt->process('bench.tpl', $stash, $fh);
31 $t->process('bench.tpl', { name => 'bob' }, $fh);
34 $tt->process('bench.tpl', $stash, $fh);
37 $t->process('bench.tpl', { name => 'bob' }, $fh);
41 $ts->render('bench', { name => 'bob' } );
45 $tsc->render('bench', { name => 'bob' } );
48 print "Very simple interpolation:\n";
49 cmpthese( $iter, { teeny => \&teeny, template_toolkit => \&plain,
50 simple => \&simple, ts_compiled => \&ts_compiled }) ;
57 <head><title>[% title %]</title></head>
63 <span>[% date %]</span>
71 my $ts = Template::Simple->new() ;
72 $ts->add_templates( { bench2 => $tmpl } ) ;
74 my $tsc = Template::Simple->new() ;
75 $tsc->add_templates( { bench2 => $tmpl } ) ;
76 $tsc->compile( 'bench2' ) ;
78 my $tt = Template::Teeny->new({ include_path => ['t/tpl'] });
79 my $stash = Template::Teeny::Stash->new({ title => q{Bobs Blog} });
81 my $post1 = Template::Teeny::Stash->new({ date => 'Today', title => 'hehe' });
82 my $post2 = Template::Teeny::Stash->new({ date => '3 Days ago', title => 'Something new' });
83 $stash->add_section('post', $post1);
84 $stash->add_section('post', $post2);
86 my $t = Template->new({ INCLUDE_PATH => 't/tpl', COMPILE_EXT => '.tc' });
88 open my $fh, '>/dev/null';
93 { title => 'hehe', date => 'Today' },
94 { date => '3 Days ago', title => 'Something new' },
101 $tt->process('bench2-teeny.tpl', $stash, $fh);
104 $t->process('bench2-tt.tpl', $tt_vars, $fh);
108 $ts->render('bench2', $tt_vars );
112 $tsc->render('bench2', $tt_vars );
115 print "\nLoop and interpolation:\n";
116 cmpthese( $iter, { teeny => \&teeny2, template_toolkit => \&plain2,
117 simple => \&simple2, ts_compiled => \&ts_compiled2 }) ;