Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 100 lines (90 sloc) 2.513 kb
05e66c90 »
2012-08-17 Add profiling setup
1 coffeemugg = require './src/coffeemugg'
2 profiler = require 'profiler'
3
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 coffeemugg_template = ->
16 @doctype 5
17 @html lang: 'en', ->
18 @head ->
19 @meta charset: 'utf-8'
20 @title data.title
21 @style '''
22 body {font-family: "sans-serif"}
23 section, header {display: block}
24 '''
25 @body ->
26 @section ->
27 @header ->
28 @h1 data.title
29 if data.inspired
30 @p 'Create a witty example'
31 else
32 @p 'Go meta'
33 @ul ->
34 for user in data.users
35 @li user.name
36 @li -> @a href: "mailto:#{user.email}", -> user.email
37
38 coffeemugg_template_args = (data) ->
39 @doctype 5
40 @html lang: 'en', ->
41 @head ->
42 @meta charset: 'utf-8'
43 @title data.title
44 @style '''
45 body {font-family: "sans-serif"}
46 section, header {display: block}
47 '''
48 @body ->
49 @section ->
50 @header ->
51 @h1 data.title
52 if data.inspired
53 @p 'Create a witty example'
54 else
55 @p 'Go meta'
56 @ul ->
57 for user in data.users
58 @li user.name
59 @li -> @a href: "mailto:#{user.email}", -> user.email
60
61 coffeemugg_template_context = ->
62 @doctype 5
63 @html lang: 'en', ->
64 @head ->
65 @meta charset: 'utf-8'
66 @title @data.title
67 @style '''
68 body {font-family: "sans-serif"}
69 section, header {display: block}
70 '''
71 @body ->
72 @section ->
73 @header ->
74 @h1 @data.title
75 if @data.inspired
76 @p 'Create a witty example'
77 else
78 @p 'Go meta'
79 @ul ->
80 for user in @data.users
81 @li user.name
82 @li -> @a href: "mailto:#{user.email}", -> user.email
83
84
85 benchmark = (title, code) ->
86 start = new Date
87 profiler.resume()
88 for i in [1..15000]
89 code()
90 profiler.pause()
91 log "#{title}: #{new Date - start} ms"
92
93 @run = ->
94 benchmark 'CoffeeMugg (none)', -> coffeemugg.render coffeemugg_template
95 #benchmark 'CoffeeMugg (args)', -> coffeemugg.render coffeemugg_template_args, null, data
96 #benchmark 'CoffeeMugg (context)', -> coffeemugg.render coffeemugg_template_context, context: {data: data}
97 #benchmark 'CoffeeMugg (format) (none)', -> coffeemugg.render coffeemugg_template, format: on
98
99 @run()
Something went wrong with that request. Please try again.