From: Uri Guttman Date: Sun, 21 Dec 2008 21:22:00 +0000 (-0500) Subject: cleaned up a bug when timing the compiled templates. pasted in a new X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=107d449430218653cdae78a6588ec35e66137492;p=urisagit%2FTemplate-Simple.git cleaned up a bug when timing the compiled templates. pasted in a new compiled example. munged what tests to do and print. --- diff --git a/bench.pl b/bench.pl index 8dc354c..de2908f 100644 --- a/bench.pl +++ b/bench.pl @@ -7,12 +7,13 @@ use Template::Simple ; 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 = <add_templates( { bench => $template } ) ; - -my $x = <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 ) }, } ) ; @@ -64,11 +65,6 @@ exit ; no warnings ; - -sub rendered { - -} - sub joined { no warnings ; @@ -156,11 +152,6 @@ no warnings ; } -sub append { - -} - - sub concat { no warnings ; @@ -237,6 +228,7 @@ no warnings ; . "\nFooter\n" ; } + $out ; } ; @@ -244,9 +236,6 @@ no warnings ; } sub append { - -no warnings ; - my( $data ) = @_ ; my $out ; @@ -259,6 +248,7 @@ no warnings ; next ; } + $out .= ref $data ne 'HASH' ? $data : "Header\nVal 1: " . @@ -274,15 +264,17 @@ no warnings ; next ; } + $out .= ref $data ne 'HASH' ? $data : "\n\tLevel: " . $data->{level} . "\n" ; + } - $out .= + $out .= ref $data ne 'HASH' ? $data : "\n" ; my @data = $data->{opt} ; @@ -293,26 +285,28 @@ no warnings ; 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 ) = @_ ;