use Benchmark qw( timethese cmpthese ) ;
use Data::Dumper ;
-my @dims = @ARGV ? (shift, shift) : ( 3, 5) ;
+my @dims = @ARGV ? (shift, shift) : ( 3, 5 ) ;
my $data = generate_data( @dims ) ;
#print Dumper $data ;
my $tmpl = Template::Simple->new() ;
+my $comp = Template::Simple->new() ;
my $template = <<TMPL ;
Header
TMPL
$tmpl->add_templates( { bench => $template } ) ;
-
-my $x = <<XXX ;
-XXX
-
my $rendered = $tmpl->render( 'bench', $data ) ;
-#$tmpl->compile( 'bench', $data ) ;
-#print $tmpl->get_source( 'bench' ) ;
-#my $comp_rendered = $tmpl->render( 'bench', $data ) ;
-#my $ok = $$rendered eq $$comp_rendered ;
+$comp->add_templates( { bench => $template } ) ;
+$comp->compile( 'bench' ) ;
+my $comp_rendered = $comp->render( 'bench', $data ) ;
+#print $comp->get_source( 'bench' ) ;
-my $joined = joined( $data ) ;
-my $appended = joined( $data ) ;
+my $ok = $$rendered eq $$comp_rendered ;
+print "OK comp [$ok]\n" ;
-my $ok = $$rendered eq $$appended ;
-
-print "OK [$ok]\n" ;
+my $appended = append( $data ) ;
+$ok = $$rendered eq $$appended ;
+print "OK append [$ok]\n" ;
+#print $$rendered ;
+#my $joined = joined( $data ) ;
# print $$rendered ;
# print "----\n" ;
# print $$joined ;
-#print $$comp_rendered ;
+# print $$comp_rendered ;
cmpthese( shift || -2,
{
render => sub { my $x = $tmpl->render( 'bench', $data ) },
- joined => sub { my $x = joined( $data ) },
- concat => sub { my $x = concat( $data ) },
+# joined => sub { my $x = joined( $data ) },
+# concat => sub { my $x = concat( $data ) },
append => sub { my $x = append( $data ) },
+# compiler => sub { my $x = $comp->compile( 'bench' ) },
+ compiled => sub { my $x = $comp->render( 'bench', $data ) },
}
) ;
no warnings ;
-
-sub rendered {
-
-}
-
sub joined {
no warnings ;
}
-sub append {
-
-}
-
-
sub concat {
no warnings ;
.
"\nFooter\n" ;
}
+
$out ;
} ;
}
sub append {
-
-no warnings ;
-
my( $data ) = @_ ;
my $out ;
next ;
}
+
$out .= ref $data ne 'HASH' ? $data :
"Header\nVal 1: "
.
next ;
}
+
$out .= ref $data ne 'HASH' ? $data :
"\n\tLevel: "
.
$data->{level}
.
"\n" ;
+
}
- $out .=
+ $out .= ref $data ne 'HASH' ? $data :
"\n" ;
my @data = $data->{opt} ;
next ;
}
+
$out .= ref $data ne 'HASH' ? $data :
"\n\tOptional Level: "
.
$data->{level}
.
"\n" ;
+
}
- $out .=
+ $out .= ref $data ne 'HASH' ? $data :
"\nVal 2: "
.
$data->{val_2}
.
"\nFooter\n" ;
+
}
return \$out ;
}
-
sub generate_data {
my( $outer_size, $inner_size ) = @_ ;