]> Dogcows Code - chaz/p5-CGI-Ex/blobdiff - samples/benchmark/bench_various_templaters.pl
CGI::Ex 2.14
[chaz/p5-CGI-Ex] / samples / benchmark / bench_various_templaters.pl
index 2ba98e2edc83f3632db5e376c3c3279f1701a8e2..e052f91997dbf72acfebc737fc64bea4d25e8b3a 100644 (file)
@@ -14,7 +14,9 @@ use Template::Stash;
 use Template::Stash::XS;
 use Template::Parser::CET;
 use Text::Template;
+use Text::Tmpl;
 use HTML::Template;
+use HTML::Template::Compiled;
 use HTML::Template::Expr;
 use HTML::Template::JIT;
 use CGI::Ex::Dump qw(debug);
@@ -30,13 +32,17 @@ my $names = {
   CETX         => 'CGI::Ex::Template::XS using TT interface',
   CETH         => 'CGI::Ex::Template using HTML::Template interface',
   CETXH        => 'CGI::Ex::Template::XS using HTML::Template interface',
+  CETXHp       => 'CGI::Ex::Template::XS using HTML::Template interface - Perl code eval based',
+  CETXTMPL     => 'CGI::Ex::Temmplate::XS using Text::Tmpl interface',
   HT           => 'HTML::Template',
   HTE          => 'HTML::Template::Expr',
   HTJ          => 'HTML::Template::JIT - Compiled to C template',
+  HTC          => 'HTML::Template::Compiled',
   TextTemplate => 'Text::Template - Perl code eval based',
   TT           => 'Template::Toolkit',
   TTX          => 'Template::Toolkit with Stash::XS',
   TTXCET       => 'Template::Toolkit with Stash::XS and Template::Parser::CET',
+  TMPL         => 'Text::Tmpl - Engine is C based',
 
   mem          => 'Compiled in memory',
   file         => 'Loaded from file',
@@ -159,6 +165,31 @@ $filler
 {\$shell_footer}
 DOC
 
+###----------------------------------------------------------------###
+### Tmpl style template
+
+my $content_tmpl = <<"DOC";
+<!--echo \$shell_header-->
+<!--echo \$shell_start-->
+$filler
+
+<!-- if \$foo -->
+This is some text.
+<!-- endif -->
+
+<!-- loop "a_stuff" --><!-- echo \$name --><!-- endloop -->
+<!-- echo \$pass_in_something -->
+
+$filler
+<!-- echo \$shell_end -->
+<!-- echo \$shell_footer -->
+DOC
+
+if (open (my $fh, ">$dir/foo.tmpl")) {
+    print $fh $content_tmpl;
+    close $fh;
+}
+
 ###----------------------------------------------------------------###
 ### The TT interface allows for a single object to be cached and reused.
 
@@ -168,6 +199,10 @@ my $ct  = CGI::Ex::Template->new(    INCLUDE_PATH => \@dirs, VARIABLES => $stash
 my $ctx = CGI::Ex::Template::XS->new(INCLUDE_PATH => \@dirs, VARIABLES => $stash_t);
 
 ###----------------------------------------------------------------###
+my %CETH_DOCUMENTS;
+my %CETXH_DOCUMENTS;
+my %CETXHp_DOCUMENTS;
+
 
 my $tests = {
 
@@ -182,27 +217,64 @@ my $tests = {
         my $tt = Template->new(INCLUDE_PATH => \@dirs, STASH => Template::Stash::XS->new($stash_t), COMPILE_DIR => $dir2);
         my $out = ""; $tt->process('foo.tt', $form, \$out); $out;
     },
-    CET_file => sub {
-        my $t = CGI::Ex::Template->new(INCLUDE_PATH => \@dirs, VARIABLES => $stash_t, COMPILE_DIR  => $dir2);
-        my $out = ''; $t->process('foo.tt', $form, \$out); $out;
-    },
-    CETX_file => sub {
-        my $t = CGI::Ex::Template::XS->new(INCLUDE_PATH => \@dirs, VARIABLES => $stash_t, COMPILE_DIR => $dir2);
-        my $out = ''; $t->process('foo.tt', $form, \$out); $out;
-    },
+#    CET_file => sub {
+#        my $t = CGI::Ex::Template->new(INCLUDE_PATH => \@dirs, VARIABLES => $stash_t, COMPILE_DIR  => $dir2);
+#        my $out = ''; $t->process('foo.tt', $form, \$out); $out;
+#    },
+#    CETX_file => sub {
+#        my $t = CGI::Ex::Template::XS->new(INCLUDE_PATH => \@dirs, VARIABLES => $stash_t, COMPILE_DIR => $dir2);
+#        my $out = ''; $t->process('foo.tt', $form, \$out); $out;
+#    },
 
     CETH_file => sub {
-        my $ht = CGI::Ex::Template->new(type => 'filename', source => "foo.ht", file_cache => 1, path => \@dirs, file_cache_dir => $dir2);
+        my $ht = CGI::Ex::Template->new(type => 'filename', source => "foo.ht", file_cache => 1, path => \@dirs, file_cache_dir => $dir2, CASE_SENSITVE=>1);
+        $ht->{'_documents'} = \%CETH_DOCUMENTS;
         $ht->param($stash_ht); $ht->param($form); my $out = $ht->output;
     },
     CETXH_file => sub {
-        my $ht = CGI::Ex::Template::XS->new(type => 'filename', source => "foo.ht", file_cache => 1, path => \@dirs, file_cache_dir => $dir2);
+        my $ht = CGI::Ex::Template::XS->new(type => 'filename', source => "foo.ht", file_cache => 1, path => \@dirs, file_cache_dir => $dir2,
+                                            CASE_SENSITVE=>1);
+        $ht->{'_documents'} = \%CETXH_DOCUMENTS;
+        $ht->param($stash_ht); $ht->param($form); my $out = $ht->output;
+    },
+    CETXHp_file => sub {
+        my $ht = CGI::Ex::Template::XS->new(type => 'filename', source => "foo.ht", file_cache => 1, path => \@dirs, file_cache_dir => $dir2,
+                                            CASE_SENSITVE=>1, compile_perl => 1, cache => 1);
+        $ht->{'_documents'} = \%CETXHp_DOCUMENTS;
         $ht->param($stash_ht); $ht->param($form); my $out = $ht->output;
     },
     HT_file => sub {
-        my $ht = HTML::Template->new(type => 'filename', source => "foo.ht", file_cache => 1, path => \@dirs, file_cache_dir => $dir2);
+        my $ht = HTML::Template->new(type => 'filename', source => "foo.ht", file_cache => 1, path => \@dirs, file_cache_dir => $dir2, CASE_SENSITVE=>1);
+        $ht->param($stash_ht); $ht->param($form); my $out = $ht->output;
+    },
+    HTC_file => sub {
+        my $ht = HTML::Template::Compiled->new(type => 'filename', source => "foo.ht", file_cache => 1, path => \@dirs, file_cache_dir => $dir2, CASE_SENSITVE=>1);
         $ht->param($stash_ht); $ht->param($form); my $out = $ht->output;
     },
+    TMPL_file => sub {
+        my $tt = Text::Tmpl->new;
+        for my $ref (@{ $stash_ht->{'a_stuff'} }) {
+            $tt->loop_iteration('a_stuff')->set_values($ref);
+        }
+        $tt->set_values($stash_ht);
+        $tt->set_values($form);
+        $tt->set_delimiters('<!--','-->');
+        $tt->set_dir("$dir/");
+        $tt->set_strip(0);
+        my $out = $tt->parse_file("foo.tmpl");
+    },
+#    CETXTMPL_file => sub {
+#        my $tt = CGI::Ex::Template::XS->new;
+#        for my $ref (@{ $stash_ht->{'a_stuff'} }) {
+#            $tt->loop_iteration('a_stuff')->set_values($ref);
+#        }
+#        $tt->set_values($stash_ht);
+#        $tt->set_values($form);
+#        $tt->set_delimiters('<!--','-->');
+#        $tt->set_dir("$dir/");
+#        $tt->set_strip(0);
+#        my $out = $tt->parse_file("foo.tmpl");
+#    },
 
     ###----------------------------------------------------------------###
     ### str infers that we are pulling from a string reference
@@ -227,58 +299,92 @@ my $tests = {
         my $t = Template->new(STASH => Template::Stash::XS->new($stash_t), PARSER => Template::Parser::CET->new);
         my $out = ""; $t->process(\$content_tt, $form, \$out); $out;
     },
-    CET_str => sub {
-        my $t = CGI::Ex::Template->new(VARIABLES => $stash_t);
-        my $out = ""; $t->process(\$content_tt, $form, \$out); $out;
-    },
-    CETX_str => sub {
-        my $t = CGI::Ex::Template::XS->new(VARIABLES => $stash_t);
-        my $out = ""; $t->process(\$content_tt, $form, \$out); $out;
-    },
+#    CET_str => sub {
+#        my $t = CGI::Ex::Template->new(VARIABLES => $stash_t);
+#        my $out = ""; $t->process(\$content_tt, $form, \$out); $out;
+#    },
+#    CETX_str => sub {
+#        my $t = CGI::Ex::Template::XS->new(VARIABLES => $stash_t);
+#        my $out = ""; $t->process(\$content_tt, $form, \$out); $out;
+#    },
 
     CETH_str => sub {
-        my $ht = CGI::Ex::Template->new(    type => 'scalarref', source => \$content_ht);
+        my $ht = CGI::Ex::Template->new(    type => 'scalarref', source => \$content_ht, CASE_SENSITVE=>1);
+        $ht->{'_documents'} = \%CETH_DOCUMENTS;
         $ht->param($stash_ht); $ht->param($form); my $out = $ht->output;
     },
     CETXH_str => sub {
-        my $ht = CGI::Ex::Template::XS->new(type => 'scalarref', source => \$content_ht);
+        my $ht = CGI::Ex::Template::XS->new(type => 'scalarref', source => \$content_ht, CASE_SENSITVE=>1);
+        $ht->{'_documents'} = \%CETXH_DOCUMENTS;
+        $ht->param($stash_ht); $ht->param($form); my $out = $ht->output;
+    },
+    CETXHp_str => sub {
+        my $ht = CGI::Ex::Template::XS->new(type => 'scalarref', source => \$content_ht, CASE_SENSITVE=>1, compile_perl => 1, cache => 1);
+        $ht->{'_documents'} = \%CETXHp_DOCUMENTS;
         $ht->param($stash_ht); $ht->param($form); my $out = $ht->output;
     },
     HT_str => sub {
-        my $ht = HTML::Template->new(       type => 'scalarref', source => \$content_ht);
+        my $ht = HTML::Template->new(       type => 'scalarref', source => \$content_ht, CASE_SENSITVE=>1);
         $ht->param($stash_ht); $ht->param($form); my $out = $ht->output;
     },
     HTE_str => sub {
-        my $ht = HTML::Template::Expr->new( type => 'scalarref', source => \$content_ht);
+        my $ht = HTML::Template::Expr->new( type => 'scalarref', source => \$content_ht, CASE_SENSITVE=>1);
+        $ht->param($stash_ht); $ht->param($form); my $out = $ht->output;
+    },
+    HTC_str => sub {
+        my $ht = HTML::Template::Compiled->new(type => 'scalarref', source => \$content_ht, CASE_SENSITVE=>1);
         $ht->param($stash_ht); $ht->param($form); my $out = $ht->output;
     },
+    TMPL_str => sub {
+        my $tt = Text::Tmpl->new;
+        for my $ref (@{ $stash_ht->{'a_stuff'} }) {
+            $tt->loop_iteration('a_stuff')->set_values($ref);
+        }
+        $tt->set_values($stash_ht);
+        $tt->set_values($form);
+        $tt->set_delimiters('<!--','-->');
+        $tt->set_dir("$dir/");
+        $tt->set_strip(0);
+        my $out = $tt->parse_string($content_tmpl);
+    },
 
     ###----------------------------------------------------------------###
     ### mem indicates that the compiled form is stored in memory
 
     TT_mem   => sub { my $out = ""; $tt->process( 'foo.tt', $form, \$out); $out },
     TTX_mem  => sub { my $out = ""; $ttx->process('foo.tt', $form, \$out); $out },
-    CET_mem  => sub { my $out = ""; $ct->process( 'foo.tt', $form, \$out); $out },
-    CETX_mem => sub { my $out = ""; $ctx->process('foo.tt', $form, \$out); $out },
+#    CET_mem  => sub { my $out = ""; $ct->process( 'foo.tt', $form, \$out); $out },
+#    CETX_mem => sub { my $out = ""; $ctx->process('foo.tt', $form, \$out); $out },
 
     CETH_mem => sub {
-        my $ht = CGI::Ex::Template->new(    filename => "foo.ht", path => \@dirs, cache => 1);
+        my $ht = CGI::Ex::Template->new(    filename => "foo.ht", path => \@dirs, cache => 1, CASE_SENSITVE=>1);
+        $ht->{'_documents'} = \%CETH_DOCUMENTS;
         $ht->param($stash_ht); $ht->param($form); my $out = $ht->output;
     },
     CETXH_mem => sub {
-        my $ht = CGI::Ex::Template::XS->new(filename => "foo.ht", path => \@dirs, cache => 1);
+        my $ht = CGI::Ex::Template::XS->new(filename => "foo.ht", path => \@dirs, cache => 1, CASE_SENSITVE=>1);
+        $ht->{'_documents'} = \%CETXH_DOCUMENTS;
+        $ht->param($stash_ht); $ht->param($form); my $out = $ht->output;
+    },
+    CETXHp_mem => sub {
+        my $ht = CGI::Ex::Template::XS->new(filename => "foo.ht", path => \@dirs, cache => 1, CASE_SENSITVE=>1, compile_perl => 1, cache => 1);
+        $ht->{'_documents'} = \%CETXHp_DOCUMENTS;
         $ht->param($stash_ht); $ht->param($form); my $out = $ht->output;
     },
     HT_mem => sub {
-        my $ht = HTML::Template->new(       filename => "foo.ht", path => \@dirs, cache => 1);
+        my $ht = HTML::Template->new(       filename => "foo.ht", path => \@dirs, cache => 1, CASE_SENSITVE=>1);
+        $ht->param($stash_ht); $ht->param($form); my $out = $ht->output;
+    },
+    HTC_mem => sub {
+        my $ht = HTML::Template::Compiled->new(       filename => "foo.ht", path => \@dirs, cache => 1, CASE_SENSITVE=>1);
         $ht->param($stash_ht); $ht->param($form); my $out = $ht->output;
     },
     HTE_mem => sub {
-        my $ht = HTML::Template::Expr->new( filename => "foo.ht", path => \@dirs, cache => 1);
+        my $ht = HTML::Template::Expr->new( filename => "foo.ht", path => \@dirs, cache => 1, CASE_SENSITVE=>1);
         $ht->param($stash_ht); $ht->param($form); my $out = $ht->output;
     },
     HTJ_mem => sub { # this is interesting - it is compiled - but it is pulled into memory just once
-        my $ht = HTML::Template::JIT->new(  filename => "foo.ht", path => \@dirs, jit_path => $dir2);
+        my $ht = HTML::Template::JIT->new(  filename => "foo.ht", path => \@dirs, jit_path => $dir2, CASE_SENSITVE=>1);
         $ht->param($stash_ht); $ht->param($form); my $out = $ht->output;
     },
 };
@@ -286,6 +392,10 @@ my $tests = {
 my $test = $tests->{'TT_str'}->();
 foreach my $name (sort keys %$tests) {
     if ($test ne $tests->{$name}->()) {
+        print "--------------------------TT_str-------\n";
+        print $test;
+        print "--------------------------$name--------\n";
+        print $tests->{$name}->();
         die "$name did not match TT_str output\n";
     }
     $name =~ /(\w+)_(\w+)/;
This page took 0.024231 seconds and 4 git commands to generate.