Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

executable file 49 lines (42 sloc) 1.226 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
#!/usr/bin/env coffee

coffeecup = require './src/coffeecup'
log = console.log

data =
  title: 'test'
  inspired: no
  users: [
    {email: 'house@gmail.com', name: 'house'}
    {email: 'cuddy@gmail.com', name: 'cuddy'}
    {email: 'wilson@gmail.com', name: 'wilson'}
  ]

coffeecup_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'
        ul ->
          for user in @users
            li user.name
            li -> a href: "mailto:#{user.email}", -> user.email

coffeecup_compiled_template = coffeecup.compile coffeecup_template

coffeecup_optimized_template = coffeecup.compile coffeecup_template, optimize: yes

benchmark = (title, code) ->
  start = new Date
  for i in [1..100000]
    code()
  log "#{title}: #{new Date - start} ms"

benchmark 'coffeecup (precompiled)', -> coffeecup_compiled_template data
benchmark 'coffeecup (precompiled, optimized)', -> coffeecup_optimized_template data
Something went wrong with that request. Please try again.