Permalink
Browse files

Benchmark refactoring.

  • Loading branch information...
mauricemach committed Sep 13, 2010
1 parent c06affd commit 9b2b6e5b36967bc768cf65c8519e23aca7aef2f5
Showing with 62 additions and 53 deletions.
  1. +4 −0 Cakefile
  2. +1 −1 README.md
  3. +57 −52 benchmark.coffee
View
@@ -1,6 +1,7 @@
exec = require('child_process').exec
coffeekup = require 'coffeekup'
render = coffeekup.render
+benchmark = require './benchmark'
task 'build', ->
exec 'coffee -c lib/coffeekup.coffee', (err) ->
@@ -68,3 +69,6 @@ task 'test', ->
comment 'Comment'
puts "\nTests: #{tests.length} | Passed: #{passed.length} | Failed: #{failed.length} | Errors: #{errors.length}"
+
+task 'benchmark', ->
+ benchmark.run()
View
@@ -77,7 +77,7 @@ Please note that even though examples were given in coffeescript, you can also u
## Caveats
-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.
+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.
## Compatibility
View
@@ -1,77 +1,82 @@
-#!/usr/bin/env coffee
-
jade = require 'jade'
coffeekup = require 'coffeekup'
jade_template = '''
-!!! 5
-html(lang="en")
- head
- title= pageTitle
- :javascript
- | if (foo) {
- | bar()
- | }
- body
- h1 Jade - node template engine
- #container
- - if (youAreUsingJade)
- p You are amazing
- - else
- p Get on it!
+ !!! 5
+ html(lang="en")
+ head
+ meta(charset="utf-8")
+ title= title
+ style
+ | body {font-family: "sans-serif"}
+ | section, header {display: block}
+ body
+ section
+ header
+ h1= title
+ - if (inspired)
+ p Create a witty example
+ - else
+ p Go meta
'''
coffeekup_template = ->
doctype 5
html lang: 'en', ->
head ->
+ meta charset: 'utf-8'
title @title
- script '''
- if (foo) {
- bar()
- }
+ style '''
+ body {font-family: "sans-serif"}
+ section, header {display: block}
'''
body ->
- h1 'Jade - node template engine'
- div id: 'container', ->
- if @you_are_using_coffeekup
- p 'You are amazing'
+ section ->
+ header ->
+ h1 @title
+ if @inspired
+ p 'Create a witty example'
else
- p 'Get on it!'
+ p 'Go meta'
-#coffeekup_template = """
-# doctype 5
-# html lang: 'en', ->
-# head ->
-# title @title
-# script '''
-# if (foo) {
-# bar()
-# }
-# '''
-# body ->
-# h1 'Jade - node template engine'
-# div id: 'container', ->
-# if @you_are_using_coffeekup
-# p 'You are amazing'
-# else
-# p 'Get on it!'
-#"""
+coffeekup_string_template = """
+ doctype 5
+ html lang: 'en', ->
+ head ->
+ meta charset: 'utf-8'
+ title @title
+ style '''
+ body {font-family: "sans-serif"}
+ section, header {display: block}
+ '''
+ body ->
+ section ->
+ header ->
+ h1 @title
+ if @inspired
+ p 'Create a witty example'
+ else
+ p 'Go meta'
+"""
benchmark = (title, code) ->
start = new Date
for i in [1..5000]
code()
puts "#{title}: #{new Date - start} ms"
-benchmark 'Jade', ->
- jade.render jade_template, {locals: {pageTitle: 'pageTitle', youAreUsingJade: yes}}
+exports.run = ->
+ benchmark 'CoffeeKup (code)', ->
+ coffeekup.render coffeekup_template, {context: {title: 'test', inspired: no}}
+
+ benchmark 'CoffeeKup (string)', ->
+ coffeekup.render coffeekup_string_template, {context: {title: 'test', inspired: no}}
-benchmark 'CoffeeKup', ->
- coffeekup.render coffeekup_template, {context: {title: 'title', you_are_using_coffeekup: yes}}
+ benchmark 'CoffeeKup (string, cache on)', ->
+ coffeekup.render coffeekup_template, {context: {title: 'test', inspired: no}, cache: on}
-benchmark 'Jade (cached)', ->
- jade.render jade_template, {locals: {pageTitle: 'pageTitle', youAreUsingJade: yes}, cache: yes, filename: 'aaa'}
+ benchmark 'Jade', ->
+ jade.render jade_template, {locals: {title: 'test', inspired: no}}
-benchmark 'CoffeeKup (cached)', ->
- coffeekup.render coffeekup_template, {context: {title: 'title', you_are_using_coffeekup: yes}, cache: yes}
+ benchmark 'Jade (cache on)', ->
+ jade.render jade_template, {locals: {title: 'test', inspired: no}, cache: on, filename: 'test'}

0 comments on commit 9b2b6e5

Please sign in to comment.