github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

tom-lpsd / ruby-html-template-pro

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 1
    • 1
  • Source
  • Commits
  • Network (1)
  • Issues (0)
  • Downloads (3)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (3)
    • REL-0.0.3
    • REL-0.0.2
    • REL-0.0.1
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

A port of Ruby to HTML::Template::Pro. — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

version++ 
tom-lpsd (author)
Fri Oct 02 08:37:52 -0700 2009
commit  29f4834168c1d1debb32d6f064bebf33ddeea7e1
tree    9b8c3b3dcb81f7c95214d0866a2bdf767c17972a
parent  e140136dffe75225f0f002dd383108bd138dae11
ruby-html-template-pro / benchmark.rb benchmark.rb
100644 137 lines (119 sloc) 3.78 kb
edit raw blame history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
require 'benchmark'
require 'erb'
require 'erubis'
require 'html/template/pro'
 
varset1 = { :VAR1 => 'VAR1', :VAR2 => 'VAR2', :VAR3 => 'VAR3', :VAR10 => 'VAR10' }
varset2 = { :STUFF1 => '<>"; %FA' }
 
refset1 = {
  :HASHREF0=>[],
  :HASHREF2=>[{},{}],
  :HASHREF1=>[
              {:LOOPVAR1=>'LOOP1-VAR1',:LOOPVAR2=>'LOOP1-VAR2',:LOOPVAR3=>'LOOP1-VAR3',:LOOPVAR10=>'LOOP1-VAR10'},
              {:LOOPVAR1=>'LOOP2-VAR1',:LOOPVAR2=>'LOOP2-VAR2',:LOOPVAR3=>'LOOP2-VAR3',:LOOPVAR10=>'LOOP2-VAR10'},
              {:LOOPVAR1=>'LOOP3-VAR1',:LOOPVAR2=>'LOOP3-VAR2',:LOOPVAR3=>'LOOP3-VAR3',:LOOPVAR10=>'LOOP3-VAR10'},
              {:LOOPVAR1=>'LOOP4-VAR1',:LOOPVAR2=>'LOOP4-VAR2',:LOOPVAR3=>'LOOP4-VAR3',:LOOPVAR10=>'LOOP4-VAR10'},
             ]
}
 
# -------------------------
 
def test_tmpl(file, *args)
  params = args.inject({}) do |result, item|
    result.update(item)
  end
  testname = file
  test_tmpl_complete(testname, params)
  test_tmpl_output(testname, params)
end
 
def test_tmpl_output(testname, params)
  Dir.chdir 'templates-Pro'
  file = testname
  count = 1000
 
  tmplo = HTML::Template::Pro.new(:filename => file + '.tmpl',
                                  :die_on_bad_params => false,
                                  :strict => false,
                                  :case_sensitive => false,
                                  :loop_context_vars => true
                                  )
  tmplo.param(params);
 
  File.open('/dev/null', 'w') do |file|
    puts "Template::Pro " + '-' * 40
    puts Benchmark::CAPTION
    puts Benchmark.measure{
      count.times do
        tmplo.output(:print_to => file)
      end
    }
  end
 
  erb = ERB.new(File.read(file + '.erb'))
  File.open('/dev/null', 'w') do |file|
    puts "ERB " + '-' * 40
    puts Benchmark::CAPTION
    puts Benchmark.measure{
      count.times do
        file.puts erb.result(binding)
      end
    }
  end
 
  erubis = Erubis::FastEruby.new(File.read(file + '.erb'))
  File.open('/dev/null', 'w') do |file|
    puts "Erubis " + '-' * 40
    puts Benchmark::CAPTION
    puts Benchmark.measure{
      count.times do
        file.puts erubis.result(binding)
      end
    }
  end
 
  Dir.chdir '..'
end
 
def test_tmpl_complete(testname, params)
  Dir.chdir 'templates-Pro';
  file = testname
  count = 1000
 
  File.open('/dev/null', 'w') do |file|
    puts "Template::Pro " + '-' * 40
    puts Benchmark::CAPTION
    puts Benchmark.measure{
      count.times do
tmpl = HTML::Template::Pro.new(:filename => testname + '.tmpl',
                                       :loop_context_vars => true,
                                       :case_sensitive => false,
                                       :die_on_bad_params => false)
tmpl.param(params)
tmpl.output(:print_to => file)
      end
    }
  end
 
  File.open('/dev/null', 'w') do |file|
    puts "ERB " + '-' * 40
    puts Benchmark::CAPTION
    puts Benchmark.measure{
      count.times do
        erb = ERB.new(File.read(testname + '.erb'))
        file.puts erb.result(binding)
      end
    }
  end
 
  File.open('/dev/null', 'w') do |file|
    puts "Erubis " + '-' * 40
    puts Benchmark::CAPTION
    puts Benchmark.measure{
      count.times do
        erubis = Erubis::FastEruby.new(File.read(testname + '.erb'))
        file.puts erubis.result(binding)
      end
    }
  end
 
  Dir.chdir '..'
end
 
test_tmpl('test_var1', varset1);
test_tmpl('test_var2', varset1);
test_tmpl('test_loop1', varset1, refset1);
test_tmpl('test_loop2', varset1, refset1);
 
__END__
test_tmpl('test_var3', varset1, varset2);
test_tmpl('test_if1', varset1);
test_tmpl('test_if2', varset1);
test_tmpl('test_if3', refset1);
test_tmpl('test_loop3', varset1, refset1);
test_tmpl('test_loop4', varset1, refset1);
test_tmpl('test_loop5', varset1, refset1);
 
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server