Skip to content

Instantly share code, notes, and snippets.

@gugod
Created December 17, 2008 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gugod/37042 to your computer and use it in GitHub Desktop.
Save gugod/37042 to your computer and use it in GitHub Desktop.
Benchmarking Markapl and Tempate::Declare
#!/usr/bin/env perl
use lib '.';
use lib '/Users/gugod/git/Markapl/lib';
use lib 'lib';
# use Benchmark::Forking qw( cmpthese );
use Benchmark qw( cmpthese );
use MyTDView;
use Template::Declare;
Template::Declare->init( roots => [ MyTDView ]);
use Template::Declare::Tags;
use MyMarkaplView;
cmpthese(
10000,
{
'printf' => sub { "<p>Hello</p>"; },
'Markapl 1' => sub { MyMarkaplView->render("test1"); },
'Markapl 2' => sub { MyMarkaplView->render("test2"); },
'Markapl 3' => sub { MyMarkaplView->render("test3"); },
'Markapl 4' => sub { MyMarkaplView->render("test3"); },
'TD 1' => sub { Template::Declare->show("test1"); },
'TD 2' => sub { Template::Declare->show("test2"); },
'TD 3' => sub { Template::Declare->show("test3"); },
'TD 4' => sub { Template::Declare->show("test4"); },
'TD 5' => sub { Template::Declare->show("test4"); },
}
);
package MyMarkaplView;
use strict;
use warnings;
use Markapl;
template test1 => sub {
p { "Hello" }
};
template test2 => sub {
p (id => "test") { "Hello" }
};
template test3 => sub {
p ("#test") { "Hello" }
};
template test4 => sub {
my $class = "foo";
for (0..3) {
div(class => "salut $class") { "Hello, $_" }
}
};
1;
package MyTDView;
use strict;
use warnings;
use base 'Template::Declare';
use Template::Declare::Tags;
template test1 => sub {
p { "Hello" }
};
template test2 => sub {
p { attr { id => "test2" }; "Hello" }
};
template test3 => sub {
p { id is "test2"; "Hello" }
};
template test4 => sub {
with (id => "test2"), p { "Hello" }
};
template test5 => sub {
my $class = "foo";
for(0..3) {
with(class => "salut $_"), div { "Hello, $_" }
}
};
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment