Skip to content
This repository
Browse code

Benchmark refactoring.

  • Loading branch information...
commit 9b2b6e5b36967bc768cf65c8519e23aca7aef2f5 1 parent c06affd
Maurice Machado authored September 13, 2010
4  Cakefile
... ...
@@ -1,6 +1,7 @@
1 1
 exec = require('child_process').exec
2 2
 coffeekup = require 'coffeekup'
3 3
 render = coffeekup.render
  4
+benchmark = require './benchmark'
4 5
 
5 6
 task 'build', ->
6 7
   exec 'coffee -c lib/coffeekup.coffee', (err) ->
@@ -68,3 +69,6 @@ task 'test', ->
68 69
       comment 'Comment'
69 70
 
70 71
   puts "\nTests: #{tests.length} | Passed: #{passed.length} | Failed: #{failed.length} | Errors: #{errors.length}"
  72
+
  73
+task 'benchmark', ->
  74
+  benchmark.run()
2  README.md
Source Rendered
@@ -77,7 +77,7 @@ Please note that even though examples were given in coffeescript, you can also u
77 77
 
78 78
 ## Caveats
79 79
 
80  
-Like Markaby, not the fastest horse in the stable. Run benchmark.coffee for details. In the context of node's screaming performance though, maybe it won't matter as much as it did for Markaby in the MRI. Your feedback is appreciated.
  80
+Like Markaby, not the fastest horse in the stable. Run "cake benchmark" for details. In the context of node's screaming performance though, maybe it won't matter as much as it did for Markaby in the MRI. Your feedback is appreciated.
81 81
 
82 82
 ## Compatibility
83 83
 
109  benchmark.coffee
... ...
@@ -1,62 +1,63 @@
1  
-#!/usr/bin/env coffee
2  
-
3 1
 jade = require 'jade'
4 2
 coffeekup = require 'coffeekup'
5 3
 
6 4
 jade_template = '''
7  
-!!! 5
8  
-html(lang="en")
9  
-  head
10  
-    title= pageTitle
11  
-    :javascript
12  
-      | if (foo) {
13  
-      |    bar()
14  
-      | }
15  
-  body
16  
-    h1 Jade - node template engine
17  
-    #container
18  
-      - if (youAreUsingJade)
19  
-        p You are amazing
20  
-      - else
21  
-        p Get on it!
  5
+  !!! 5
  6
+  html(lang="en")
  7
+    head
  8
+      meta(charset="utf-8")
  9
+      title= title
  10
+      style
  11
+        | body {font-family: "sans-serif"}
  12
+        | section, header {display: block}
  13
+    body
  14
+      section
  15
+        header
  16
+          h1= title
  17
+        - if (inspired)
  18
+          p Create a witty example
  19
+        - else
  20
+          p Go meta
22 21
 '''
23 22
 
24 23
 coffeekup_template = ->
25 24
   doctype 5
26 25
   html lang: 'en', ->
27 26
     head ->
  27
+      meta charset: 'utf-8'
28 28
       title @title
29  
-      script '''
30  
-        if (foo) {
31  
-           bar()
32  
-        }
  29
+      style '''
  30
+        body {font-family: "sans-serif"}
  31
+        section, header {display: block}
33 32
       '''
34 33
     body ->
35  
-      h1 'Jade - node template engine'
36  
-      div id: 'container', ->
37  
-        if @you_are_using_coffeekup
38  
-          p 'You are amazing'
  34
+      section ->
  35
+        header ->
  36
+          h1 @title
  37
+        if @inspired
  38
+          p 'Create a witty example'
39 39
         else
40  
-          p 'Get on it!'
  40
+          p 'Go meta'
41 41
 
42  
-#coffeekup_template = """
43  
-#  doctype 5
44  
-#  html lang: 'en', ->
45  
-#    head ->
46  
-#      title @title
47  
-#      script '''
48  
-#        if (foo) {
49  
-#           bar()
50  
-#        }
51  
-#      '''
52  
-#    body ->
53  
-#      h1 'Jade - node template engine'
54  
-#      div id: 'container', ->
55  
-#        if @you_are_using_coffeekup
56  
-#          p 'You are amazing'
57  
-#        else
58  
-#          p 'Get on it!'
59  
-#"""
  42
+coffeekup_string_template = """
  43
+  doctype 5
  44
+  html lang: 'en', ->
  45
+    head ->
  46
+      meta charset: 'utf-8'
  47
+      title @title
  48
+      style '''
  49
+        body {font-family: "sans-serif"}
  50
+        section, header {display: block}
  51
+      '''
  52
+    body ->
  53
+      section ->
  54
+        header ->
  55
+          h1 @title
  56
+        if @inspired
  57
+          p 'Create a witty example'
  58
+        else
  59
+          p 'Go meta'
  60
+"""
60 61
 
61 62
 benchmark = (title, code) ->
62 63
   start = new Date
@@ -64,14 +65,18 @@ benchmark = (title, code) ->
64 65
     code()
65 66
   puts "#{title}: #{new Date - start} ms"
66 67
 
67  
-benchmark 'Jade', ->
68  
-  jade.render jade_template, {locals: {pageTitle: 'pageTitle', youAreUsingJade: yes}}
  68
+exports.run = ->
  69
+  benchmark 'CoffeeKup (code)', ->
  70
+    coffeekup.render coffeekup_template, {context: {title: 'test', inspired: no}}
  71
+
  72
+  benchmark 'CoffeeKup (string)', ->
  73
+    coffeekup.render coffeekup_string_template, {context: {title: 'test', inspired: no}}
69 74
 
70  
-benchmark 'CoffeeKup', ->
71  
-  coffeekup.render coffeekup_template, {context: {title: 'title', you_are_using_coffeekup: yes}}
  75
+  benchmark 'CoffeeKup (string, cache on)', ->
  76
+    coffeekup.render coffeekup_template, {context: {title: 'test', inspired: no}, cache: on}
72 77
 
73  
-benchmark 'Jade (cached)', ->
74  
-  jade.render jade_template, {locals: {pageTitle: 'pageTitle', youAreUsingJade: yes}, cache: yes, filename: 'aaa'}
  78
+  benchmark 'Jade', ->
  79
+    jade.render jade_template, {locals: {title: 'test', inspired: no}}
75 80
 
76  
-benchmark 'CoffeeKup (cached)', ->
77  
-  coffeekup.render coffeekup_template, {context: {title: 'title', you_are_using_coffeekup: yes}, cache: yes}
  81
+  benchmark 'Jade (cache on)', ->
  82
+    jade.render jade_template, {locals: {title: 'test', inspired: no}, cache: on, filename: 'test'}

0 notes on commit 9b2b6e5

Please sign in to comment.
Something went wrong with that request. Please try again.