/
jquery_template_benchmark.html
62 lines (56 loc) · 2.44 KB
/
jquery_template_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
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>JS Template Benchmarks: jQuery template plugin</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.template.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="report">
<h1>JS Template Benchmarks: jQuery template plugin</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>
</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 = $.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.append(story_tmp, {
name: 'jQuery Templates',
url: 'http://plugins.jquery.com/project/jquerytemplate',
source: 'http://plugins.jquery.com/files/jquery.template.js.txt'
});
};
$.benchmarks.loop_test = function(){
var comment_tmp = $.template('<li class="comment"><h5>${name}</h5><p>${body}</p></li>');
output.append('<div class="comments"><h3>Comments</h3><ul></ul></div>');
var ul = $('#output .comments:last ul:last');
var 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!"}
];
comments_length = comments.length;
for (var i=0; i < comments_length; i++){
ul.append(comment_tmp, comments[i]);
}
};
// 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>