Skip to content
This repository
Newer
Older
100755 49 lines (42 sloc) 1.226 kb
81bda8d2 » wmertens
2012-04-02 Better test for optimized vs regular templates
1 #!/usr/bin/env coffee
2
3 coffeecup = require './src/coffeecup'
4 log = console.log
5
6 data =
7 title: 'test'
8 inspired: no
9 users: [
10 {email: 'house@gmail.com', name: 'house'}
11 {email: 'cuddy@gmail.com', name: 'cuddy'}
12 {email: 'wilson@gmail.com', name: 'wilson'}
13 ]
14
15 coffeecup_template = ->
16 doctype 5
17 html lang: 'en', ->
18 head ->
19 meta charset: 'utf-8'
20 title @title
21 style '''
22 body {font-family: "sans-serif"}
23 section, header {display: block}
24 '''
25 body ->
26 section ->
27 header ->
28 h1 @title
29 if @inspired
30 p 'Create a witty example'
31 else
32 p 'Go meta'
33 ul ->
34 for user in @users
35 li user.name
36 li -> a href: "mailto:#{user.email}", -> user.email
37
38 coffeecup_compiled_template = coffeecup.compile coffeecup_template
39
40 coffeecup_optimized_template = coffeecup.compile coffeecup_template, optimize: yes
41
42 benchmark = (title, code) ->
43 start = new Date
44 for i in [1..100000]
45 code()
46 log "#{title}: #{new Date - start} ms"
47
48 benchmark 'coffeecup (precompiled)', -> coffeecup_compiled_template data
49 benchmark 'coffeecup (precompiled, optimized)', -> coffeecup_optimized_template data
Something went wrong with that request. Please try again.