/
underscore_benchmark.html
73 lines (64 loc) · 3.06 KB
/
underscore_benchmark.html
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>JS Template Benchmarks: Underscore</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="underscore.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="report">
<h1>JS Template Benchmarks: Underscore</h1>
<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>
<li>Compiled Test: <span class="stat" id="compiled_test"></span></li>
</ul>
</div>
</div>
<div id="output"></div>
<script type="text/javascript">
$(document).ready(function(){
var output_div = $('#output');
$.benchmarks = {};
$.benchmarks.test_simple = function(){
var info_tmpl = _.template('<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_div.append(info_tmpl({
name: 'Underscore',
url: 'http://documentcloud.github.com/underscore/',
source: 'http://documentcloud.github.com/underscore/underscore.js'
}));
};
$.benchmarks.loop_test = function(){
var comment_tmp = _.template('<div class="comments"><h3><%= header %></h3><ul><% _.each(comments, function(comment){ %><li class="comment"><h5><%= comment.name %></h5><p><%= comment.body %></p></li><% }); %></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!"}
]
};
output_div.append(comment_tmp(comment_view));
};
var compiled_tmpl = _.template('<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>');
$.benchmarks.compiled_test = function(){
output_div.append(compiled_tmpl({
name: 'Underscore',
url: 'http://documentcloud.github.com/underscore/',
source: 'http://documentcloud.github.com/underscore/underscore.js'
}));
}
// 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);
// $.benchmark(1000, '#compiled_test', $.benchmarks.compiled_test);
});
</script>
</body>
</html>