Editing JS - Comparing few js templates This edit will create a new revision. Your details (optional) Name Email (won’t be displayed; might be used for Gravatar) URL Test case details Title * Published (uncheck if you want to fiddle around before making the page public) Description (in case you feel further explanation is needed)(Markdown syntax is allowed) comparing: - slab - underscore - jquery template - icanhaz - handlebars (1.0.0. beta 6, see here for updates: https://github.com/wycats/handlebars.js/downloads) - mustache - mustache compiled - dotT and old version of it dotU - mote Are you a spammer? (just answer the question) Preparation code Preparation code HTML (this will be inserted in the <body> of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) <script src="https://raw.github.com/gist/ad2ca6f18fed03a899c9/799ee05bd262f47232d248f9e9ea1077939411d6/slab.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script src="http://documentcloud.github.com/underscore/underscore.js"></script> <script src="https://raw.github.com/andyet/ICanHaz.js/master/ICanHaz.js"></script> <script src="http://github.com/janl/mustache.js/raw/master/mustache.js"></script> <script src="https://github.com/downloads/wycats/handlebars.js/handlebars-1.0.0.beta.6.js"></script> <script src="http://jashkenas.github.com/coffee-script/extras/coffee-script.js"></script> <script src="http://github.com/jquery/jquery-tmpl/raw/master/jquery.tmpl.min.js"></script> <script src="http://github.com/olado/doT/raw/master/doT.js"></script> <script src="http://github.com/olado/doT/raw/master/doU.js"></script> <script src="https://raw.github.com/satchmorun/mote/master/mote.js"></script> <div class="pure"> <h1 class='header'></h1> <h2 class='header2'></h2> <h3 class='header3'></h3> <h4 class='header4'></h4> <h5 class='header5'></h5> <h6 class='header6'></h6> <ul class='list'> <li class='item'></li> </ul> </div> <!-- script src="http://github.com/douglascrockford/JSON-js/raw/master/json2.js"></script --> <script src="http://akdubya.github.com/dustjs/dist/dust-full-0.3.0.min.js"></script> <script> window.micro = "<div><h1 class='header'><%= header %></h1><h2 class='header2'><%= header2 %></h2><h3 class='header3'><%= header3 %></h3><h4 class='header4'><%= header4 %></h4><h5 class='header5'><%= header5 %></h5><h6 class='header6'><%= header6 %></h6><ul class='list'><% for (var i = 0, l = list.length; i < l; i++) { %><li class='item'><%= list[i] %></li><% } %></ul></div>"; window.mustacheTemplate = "<div><h1 class='header'>{{header}}</h1><h2 class='header2'>{{header2}}</h2><h3 class='header3'>{{header3}}</h3><h4 class='header4'>{{header4}}</h4><h5 class='header5'>{{header5}}</h5><h6 class='header6'>{{header6}}</h6><ul class='list'>{{#list}}<li class='item'>{{.}}</li>{{/list}}</ul></div>"; window.mustacheCompiled = Mustache.compile(mustacheTemplate); window.moteCompiled = mote.compile(mustacheTemplate); window.handlebarsTemplate = Handlebars.compile("<div><h1 class='header'>{{header}}</h1><h2 class='header2'>{{header2}}</h2><h3 class='header3'>{{header3}}</h3><h4 class='header4'>{{header4}}</h4><h5 class='header5'>{{header5}}</h5><h6 class='header6'>{{header6}}</h6><ul class='list'>{{#each list}}<li class='item'>{{this}}</li>{{/each}}</ul></div>"); window.underscoreTemplate = _.template(micro); window.sharedVariables = { header: "Header", header2: "Header2", header3: "Header3", header4: "Header4", header5: "Header5", header6: "Header6", list: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'] }; window.jQueryTemplate = $.template(null, "<div><h1 class='header'>{{html header}}</h1><h2 class='header2'>{{html header2}}</h2><h3 class='header3'>{{html header3}}</h3><h4 class='header4'>{{html header4}}</h4><h5 class='header5'>{{html header5}}</h5><h6 class='header6'>{{html header6}}</h6><ul class='list'>{{each list}}<li class='item'>{{html $value}}</li>{{/each}}</ul></div>"); window.slabTemplate = slab.compile("<div><h1 class='header'>{header}</h1><h2 class='header2'>{header2}</h2><h3 class='header3'>{header3}</h3><h4 class='header4'>{header4}</h4><h5 class='header5'>{header5}</h5><h6 class='header6'>{header6}</h6><ul class='list'>{each item in list}<li class='item'>{item}</li>{end}</ul></div>"); window.doTtemplate = doT.template("<div><h1 class='header'>{{= it.header }}</h1><h2 class='header2'>{{= it.header2 }}</h2><h3 class='header3'>{{= it.header3 }}</h3><h4 class='header4'>{{= it.header4 }}</h4><h5 class='header5'>{{= it.header5 }}</h5><h6 class='header6'>{{= it.header6 }}</h6><ul class='list'>{{ for (var i = 0, l = it.list.length; i < l; i++) { }}<li class='item'>{{= it.list[i] }}</li>{{ } }}</ul></div>"); window.doUtemplate = doU.template("<div><h1 class='header'>{{= it.header }}</h1><h2 class='header2'>{{= it.header2 }}</h2><h3 class='header3'>{{= it.header3 }}</h3><h4 class='header4'>{{= it.header4 }}</h4><h5 class='header5'>{{= it.header5 }}</h5><h6 class='header6'>{{= it.header6 }}</h6><ul class='list'>{{ for (var i = 0, l = it.list.length; i < l; i++) { }}<li class='item'>{{= it.list[i] }}</li>{{ } }}</ul></div>"); </script> <script id="icanhaaazzz" type="text/html"> <div><h1 class='header'>{{header}}</h1><h2 class='header2'>{{header2}}</h2><h3 class='header3'>{{header3}}</h3><h4 class='header4'>{{header4}}</h4><h5 class='header5'>{{header5}}</h5><h6 class='header6'>{{header6}}</h6><ul class='list'>{{#list}}<li class='item'>{{.}}</li>{{/list}}</ul></div> </script> Include JavaScript libraries as follows: <script src="//cdn.ext/library.js"></script> Define setup for all tests (variables, functions, arrays or other objects that will be used in the tests) (runs before each clocked test loop, outside of the timed code region) (e.g. define local test variables, reset global variables, clear canvas, etc.) (see FAQ) Define teardown for all tests (runs after each clocked test loop, outside of the timed code region) (see FAQ) Code snippets to compare Test 1 Title Async (check if this is an asynchronous test) Code slabTemplate(sharedVariables); Test 2 Title Async (check if this is an asynchronous test) Code underscoreTemplate(sharedVariables); Test 3 Title Async (check if this is an asynchronous test) Code jQueryTemplate($, { data: sharedVariables }).join(""); Test 4 Title Async (check if this is an asynchronous test) Code handlebarsTemplate(sharedVariables); Test 5 Title Async (check if this is an asynchronous test) Code doTtemplate(sharedVariables); Test 6 Title Async (check if this is an asynchronous test) Code doUtemplate(sharedVariables); Test 7 Title Async (check if this is an asynchronous test) Code ich.icanhaaazzz(sharedVariables); Test 8 Title Async (check if this is an asynchronous test) Code mustacheCompiled(sharedVariables); Test 9 Title Async (check if this is an asynchronous test) Code moteCompiled(sharedVariables); Test 10 Title Async (check if this is an asynchronous test) Code Mustache.to_html(mustacheTemplate, sharedVariables);