Skip to content

Instantly share code, notes, and snippets.

@pure
Created December 12, 2009 21:56
Show Gist options
  • Save pure/255096 to your computer and use it in GitHub Desktop.
Save pure/255096 to your computer and use it in GitHub Desktop.
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>JS Template Benchmarks: Mustache.js</title>
<link rel="stylesheet" href="styles.css" type="text/css" media="screen" charset="utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script src="jquery.benchmark.js" type="text/javascript" charset="utf-8"></script>
<script src="jquery.mustache.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="report">
<h1>JS Template Benchmarks: Mustache.js</h1>
<input id="loops" type="text" value="1000">
<a href="javascript:void(0)" onclick="$.benchmark(parseInt(document.getElementById('loops').value,10), '#simple_test', $.benchmarks.test_simple)">simple</a>
<a href="javascript:void(0)" onclick="$.benchmark(parseInt(document.getElementById('loops').value,10), '#loop_test', $.benchmarks.loop_test)">loop</a>
<a href="javascript:void(0)" onclick="$.benchmark(parseInt(document.getElementById('loops').value,10), '#compiled_test', $.benchmarks.compiled_test)">compiled</a>
<a href="javascript:void(0)" onclick="document.getElementById('output').innerHTML = ''">Reset</a>
<div id="results">
<ul>
<li>Simple Test: <span class="stat" id="simple_test"></span></li>
<li>Loop Test: <span class="stat" id="loop_test"></span></li>
</ul>
</div>
</div>
<div id="output"></div>
<script type="text/javascript">
$(document).ready(function(){
var output = $('#output');
$.benchmarks = {};
$.benchmarks.test_simple = function(){
var story_tmp = '<div class="test"><h2>This is a test of {{name}}</h2><p>The homepage is <a href="{{url}}">{{url}}</a>.</p><p>The sources is: {{source}}</p></div>';
output.append($.mustache(story_tmp, {
name: 'Underscore',
url: 'http://documentcloud.github.com/underscore/',
source: 'http://documentcloud.github.com/underscore/underscore.js'
}));
};
$.benchmarks.loop_test = function(){
var comment_tmp = '<div class="comments"><h3>{{header}}</h3><ul>{{#comments}}<li class="comment"><h5>{{name}}</h5><p>{{body}}</p></li>{{/comments}}</ul></div>';
var comment_view = {
header: "My Post Comments",
comments: [
{name: "Joe", body: "Thanks for this post!"},
{name: "Sam", body: "Thanks for this post!"},
{name: "Heather", body: "Thanks for this post!"},
{name: "Kathy", body: "Thanks for this post!"},
{name: "George", body: "Thanks for this post!"},
{name: "Joe", body: "Thanks for this post!"},
{name: "Sam", body: "Thanks for this post!"},
{name: "Heather", body: "Thanks for this post!"},
{name: "Kathy", body: "Thanks for this post!"},
{name: "George", body: "Thanks for this post!"},
{name: "Joe", body: "Thanks for this post!"},
{name: "Sam", body: "Thanks for this post!"},
{name: "Heather", body: "Thanks for this post!"},
{name: "Kathy", body: "Thanks for this post!"},
{name: "Joe", body: "Thanks for this post!"},
{name: "Sam", body: "Thanks for this post!"},
{name: "Heather", body: "Thanks for this post!"},
{name: "Kathy", body: "Thanks for this post!"},
{name: "George", body: "Thanks for this post!"},
{name: "Joe", body: "Thanks for this post!"},
{name: "Sam", body: "Thanks for this post!"},
{name: "Heather", body: "Thanks for this post!"},
{name: "Kathy", body: "Thanks for this post!"},
{name: "George", body: "Thanks for this post!"},
{name: "Joe", body: "Thanks for this post!"},
{name: "Sam", body: "Thanks for this post!"},
{name: "Heather", body: "Thanks for this post!"},
{name: "Kathy", body: "Thanks for this post!"},
{name: "George", body: "Thanks for this post!"}
]
};
output.append($.mustache(comment_tmp, comment_view));
};
// use these lines to run the benchmark tests in your browsers JS console
// $.benchmark(1000, '#simple_test', $.benchmarks.test_simple);
// $.benchmark(1000, '#loop_test', $.benchmarks.loop_test);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment