Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 208 lines (191 sloc) 5.266 kb
7177646 @mauricemach Benchmark now requires './src/coffeekup'.
authored
1 coffeekup = require './src/coffeekup'
b380123 @mauricemach Another refactoring, huge performance gains.
authored
2 jade = require 'jade'
d5e9bd4 @mauricemach Updated README.
authored
3 ejs = require 'ejs'
b380123 @mauricemach Another refactoring, huge performance gains.
authored
4 eco = require 'eco'
8b32f81 @mauricemach Added creationix's haml-js to the benchmark.
authored
5 haml = require 'haml'
4a136d2 @mauricemach First go at 0.2.4.
authored
6 log = console.log
75ee63a @mauricemach Initial import.
authored
7
b380123 @mauricemach Another refactoring, huge performance gains.
authored
8 data =
9 title: 'test'
10 inspired: no
11 users: [
12 {email: 'house@gmail.com', name: 'house'}
13 {email: 'cuddy@gmail.com', name: 'cuddy'}
14 {email: 'wilson@gmail.com', name: 'wilson'}
15 ]
75ee63a @mauricemach Initial import.
authored
16
17 coffeekup_template = ->
18 doctype 5
19 html lang: 'en', ->
20 head ->
9b2b6e5 @mauricemach Benchmark refactoring.
authored
21 meta charset: 'utf-8'
75ee63a @mauricemach Initial import.
authored
22 title @title
9b2b6e5 @mauricemach Benchmark refactoring.
authored
23 style '''
24 body {font-family: "sans-serif"}
25 section, header {display: block}
75ee63a @mauricemach Initial import.
authored
26 '''
27 body ->
9b2b6e5 @mauricemach Benchmark refactoring.
authored
28 section ->
29 header ->
30 h1 @title
31 if @inspired
32 p 'Create a witty example'
75ee63a @mauricemach Initial import.
authored
33 else
9b2b6e5 @mauricemach Benchmark refactoring.
authored
34 p 'Go meta'
b380123 @mauricemach Another refactoring, huge performance gains.
authored
35 ul ->
36 for user in @users
37 li user.name
38 li -> a href: "mailto:#{user.email}", -> user.email
75ee63a @mauricemach Initial import.
authored
39
9b2b6e5 @mauricemach Benchmark refactoring.
authored
40 coffeekup_string_template = """
41 doctype 5
42 html lang: 'en', ->
43 head ->
44 meta charset: 'utf-8'
45 title @title
46 style '''
47 body {font-family: "sans-serif"}
48 section, header {display: block}
49 '''
50 body ->
51 section ->
52 header ->
53 h1 @title
54 if @inspired
55 p 'Create a witty example'
56 else
57 p 'Go meta'
b380123 @mauricemach Another refactoring, huge performance gains.
authored
58 ul ->
59 for user in @users
60 li user.name
61 li -> a href: "mailto:\#{user.email}", -> user.email
9b2b6e5 @mauricemach Benchmark refactoring.
authored
62 """
75ee63a @mauricemach Initial import.
authored
63
8262487 @mauricemach Templates now compiled to standalone functions.
authored
64 coffeekup_compiled_template = coffeekup.compile coffeekup_template
65
b380123 @mauricemach Another refactoring, huge performance gains.
authored
66 jade_template = '''
67 !!! 5
68 html(lang="en")
69 head
70 meta(charset="utf-8")
71 title= title
72 style
73 | body {font-family: "sans-serif"}
74 | section, header {display: block}
75 body
76 section
77 header
78 h1= title
79 - if (inspired)
80 p Create a witty example
81 - else
82 p Go meta
83 ul
84 - each user in users
85 li= user.name
86 li
8b32f81 @mauricemach Added creationix's haml-js to the benchmark.
authored
87 a(href="mailto:"+user.email)= user.email
b380123 @mauricemach Another refactoring, huge performance gains.
authored
88 '''
89
4a136d2 @mauricemach First go at 0.2.4.
authored
90 jade_compiled_template = jade.compile jade_template
91
d5e9bd4 @mauricemach Updated README.
authored
92 ejs_template = '''
93 <!DOCTYPE html>
94 <html lang="en">
95 <head>
96 <meta charset="utf-8">
97 <title><%= title %></title>
98 <style>
99 body {font-family: "sans-serif"}
100 section, header {display: block}
101 </style>
102 </head>
103 <body>
104 <section>
105 <header>
106 <h1><%= title %></h1>
107 </header>
108 <% if (inspired) { %>
109 <p>Create a witty example</p>
110 <% } else { %>
111 <p>Go meta</p>
112 <% } %>
113 <ul>
114 <% for (user in users) { %>
115 <li><%= user.name %></li>
8b32f81 @mauricemach Added creationix's haml-js to the benchmark.
authored
116 <li><a href="mailto:<%= user.email %>"><%= user.email %></a></li>
d5e9bd4 @mauricemach Updated README.
authored
117 <% } %>
118 </ul>
119 </section>
120 </body>
121 </html>
122 '''
123
b380123 @mauricemach Another refactoring, huge performance gains.
authored
124 eco_template = '''
125 <!DOCTYPE html>
126 <html lang="en">
127 <head>
128 <meta charset="utf-8">
129 <title><%= @title %></title>
130 <style>
131 body {font-family: "sans-serif"}
132 section, header {display: block}
133 </style>
134 </head>
135 <body>
136 <section>
137 <header>
138 <h1><%= @title %></h1>
139 </header>
140 <% if @inspired: %>
141 <p>Create a witty example</p>
142 <% else: %>
143 <p>Go meta</p>
144 <% end %>
145 <ul>
146 <% for user in @users: %>
147 <li><%= user.name %></li>
8b32f81 @mauricemach Added creationix's haml-js to the benchmark.
authored
148 <li><a href="mailto:<%= user.email %>"><%= user.email %></a></li>
b380123 @mauricemach Another refactoring, huge performance gains.
authored
149 <% end %>
150 </ul>
151 </section>
152 </body>
153 </html>
154 '''
155
8b32f81 @mauricemach Added creationix's haml-js to the benchmark.
authored
156 haml_template = '''
157 !!! 5
158 %html{lang: "en"}
159 %head
160 %meta{charset: "utf-8"}
161 %title= title
162 :css
163 body {font-family: "sans-serif"}
164 section, header {display: block}
165 %body
166 %section
167 %header
168 %h1= title
169 :if inspired
170 %p Create a witty example
171 :if !inspired
172 %p Go meta
173 %ul
174 :each user in users
175 %li= user.name
176 %li
177 %a{href: "mailto:#{user.email}"}= user.email
178 '''
179
180 haml_template_compiled = haml(haml_template)
181
75ee63a @mauricemach Initial import.
authored
182 benchmark = (title, code) ->
183 start = new Date
184 for i in [1..5000]
185 code()
4a136d2 @mauricemach First go at 0.2.4.
authored
186 log "#{title}: #{new Date - start} ms"
75ee63a @mauricemach Initial import.
authored
187
fec0a69 @mauricemach Packaging reworked for npm 1.x.
authored
188 @run = ->
4a136d2 @mauricemach First go at 0.2.4.
authored
189 benchmark 'CoffeeKup (precompiled)', -> coffeekup_compiled_template data
190 benchmark 'Jade (precompiled)', -> jade_compiled_template data
af9cfe5 @mauricemach In `ck.render`, option `cache` is now `false` by default.
authored
191 benchmark 'haml-js (precompiled)', -> haml_template_compiled data
4a136d2 @mauricemach First go at 0.2.4.
authored
192 benchmark 'Eco', -> eco.render eco_template, data
af9cfe5 @mauricemach In `ck.render`, option `cache` is now `false` by default.
authored
193
194 console.log '\n'
195
196 benchmark 'CoffeeKup (function, cache on)', -> coffeekup.render coffeekup_template, data, cache: on
197 benchmark 'CoffeeKup (string, cache on)', -> coffeekup.render coffeekup_string_template, data, cache: on
198 benchmark 'Jade (cache on)', -> jade.render jade_template, locals: data, cache: on, filename: 'test'
d5e9bd4 @mauricemach Updated README.
authored
199 benchmark 'ejs (cache on)', -> ejs.render ejs_template, locals: data, cache: on, filename: 'test'
af9cfe5 @mauricemach In `ck.render`, option `cache` is now `false` by default.
authored
200
201 console.log '\n'
202
203 benchmark 'CoffeeKup (function, cache off)', -> coffeekup.render coffeekup_template, data
204 benchmark 'CoffeeKup (string, cache off)', -> coffeekup.render coffeekup_string_template, data, cache: off
205 benchmark 'Jade (cache off)', -> jade.render jade_template, locals: data
8b32f81 @mauricemach Added creationix's haml-js to the benchmark.
authored
206 benchmark 'haml-js', -> haml.render haml_template, locals: data
af9cfe5 @mauricemach In `ck.render`, option `cache` is now `false` by default.
authored
207 benchmark 'ejs (cache off)', -> ejs.render ejs_template, locals: data
Something went wrong with that request. Please try again.