From: Uri Guttman Date: Thu, 18 Dec 2008 18:49:46 +0000 (-0500) Subject: added bench.pl X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=540289da94d52714c6f2ffa55dc43787dee69e81;p=urisagit%2FTemplate-Simple.git added bench.pl --- diff --git a/bench.pl b/bench.pl new file mode 100644 index 0000000..2583947 --- /dev/null +++ b/bench.pl @@ -0,0 +1,137 @@ +#!/usr/local/bin/perl + +use strict ; +use warnings ; + +use Template::Simple ; +use Data::Dumper ; + +my $data = generate_data( 3, 6 ) ; +#print Dumper $data ; + +my $tmpl = Template::Simple->new() ; + +$tmpl->add_templates( { bench => <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 ; + +print "OK [$ok]\n" ; + +print $$rendered ; +print $$comp_rendered ; + +exit ; + + + + +no warnings ; + + +sub rendered { + +} + +sub map_join { + +} + +sub append { + +} + + +sub concat { + + my( $data ) = @_ ; + + my $out = do { + my $out ; + foreach my $data ( ref $data eq 'ARRAY' ? @{$data} : $data ) { + + $out .= ref $data ne 'HASH' ? $data : + "text1\n" + . + do { + my $data = $data->{nest} ; + + my $out ; + foreach my $data ( ref $data eq 'ARRAY' ? @{$data} : $data ) { + + $out .= ref $data ne 'HASH' ? $data : + "\n\tBAR is " + . + $data->{bar} + . + "\n" ; + } + + + $out ; + } + . + "\n" ; + } + $out ; + } ; + + return \$out ; +} + + +sub generate_data { + + my( $outer_size, $inner_size ) = @_ ; + + my @outer_data ; + + for my $outer ( 1 .. $outer_size ) { + + my @inner_data ; + + for my $inner ( 1 .. $inner_size ) { + + push @inner_data, { + + val_1 => ($outer x 2), + val_2 => ($inner x 3), + nest => { + level => "$outer-$inner", + }, + $inner % 2 ? () : ( + + opt => { + level => "$outer-$inner", + }, + ), + } ; + } + + push @outer_data, [@inner_data] ; + } + + return \@outer_data ; +} diff --git a/comp.pl b/comp.pl new file mode 100644 index 0000000..c1281c0 --- /dev/null +++ b/comp.pl @@ -0,0 +1,51 @@ +#!/usr/local/bin/perl + +use strict ; +use warnings ; + +use Template::Simple ; + +my $tmpl = Template::Simple->new() ; + +$tmpl->add_templates( { ddd => < [ + { + nest => { + bar => 'xxx', + }, + }, + { + nest => { + bar => 'yyy', + }, + }, + { + nest => { + bar => 'zzz', + }, + }, + ], +) ; + +$tmpl->compile('foo') ; +#$tmpl->compile('fooz') ; + +#my $rendered = $tmpl->render('foo', { foo => 2, bar => 'xxx' } ) ; + +#print "REND [$$rendered]\n" ; + +$tmpl->compile('ddd') ; +my $rendered = $tmpl->render( 'ddd', $data{ddd} ) ; + +print "REND [$$rendered]\n" ; + +print $tmpl->get_source( 'ddd' ) ; + +exit ;