1#!perl
2use strict;
3use Benchmark qw(:all);
4use Config; printf "Perl/%vd on %s\n", $^V, $Config{archname};
5
6use Text::ClearSilver;
7use HTML::Template::Pro;
8
9print "Text::ClearSilver/$Text::ClearSilver::VERSION\n";
10
11my $vars      = {
12    hoge => 1,
13    fuga => "fuga",
14};
15my @load_path = qw(benchmark/template);
16
17$vars->{hdf}{loadpaths} = \@load_path;
18
19if(0){
20    my $tcs = Text::ClearSilver->new();
21    print "T::CS\n";
22    $tcs->process('simple.cs', $vars);
23
24    print "H::T::Pro";
25    my $ht = HTML::Template::Pro->new(
26        filename       => 'simple.ht',
27        case_sensitive => 1,
28        path           => \@load_path,
29    );
30    $ht->param(%{$vars});
31    print $ht->output();
32}
33
34print "Normal processes:\n";
35cmpthese -1, {
36    'T::CS' => sub {
37        my $output;
38
39        my $tcs = Text::ClearSilver->new();
40        $tcs->process('simple.cs', $vars, \$output);
41        undef $output;
42    },
43    'H::T::Pro' => sub {
44        my $output;
45
46        my $ht = HTML::Template::Pro->new(
47            filename       => 'simple.ht',
48            case_sensitive => 1,
49            path           => \@load_path,
50        );
51        $ht->param(%{$vars});
52        $output = $ht->output();
53        undef $output;
54    },
55};
56
57
58print "Persistent processes:\n";
59my $tcs = Text::ClearSilver->new();
60my $ht = HTML::Template::Pro->new(
61    filename       => 'simple.ht',
62    case_sensitive => 1,
63    path           => \@load_path,
64);
65
66cmpthese -1, {
67    'T::CS' => sub {
68        my $output;
69        $tcs->process('simple.cs', $vars, \$output);
70        return;
71    },
72    'H::T::Pro' => sub {
73        $ht->param(%{$vars});
74        my $output = $ht->output();
75        return;
76    },
77};
78