forked from yanhaijing/template.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile-time.html
46 lines (45 loc) · 1.42 KB
/
compile-time.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>编译时间</title>
<style>
table{border-collapse: collapse;}
td{border: 1px solid #000;}
</style>
</head>
<body>
<div id="wp">正在执行,稍等。。。</div>
<script id="tpl" type="text/html">
<table>
<caption>for循环输出两次</caption>
<%var test = '输出自定义变量';%>
<%for (var i = 0; i < 2; i++) {%>
<tr><td><%=html%>默认</td><td><%=html%></td></tr>
<tr><td><%:h=html>html转义</td><td><%:h=html%></td></tr>
<tr><td><%:=html>不转义</td><td><%:=html%></td></tr>
<tr><td><%:u=url>URI转义</td><td><%:u=url%></td></tr>
<tr><td>var</td><td><%:=test%></td></tr>
<tr><td><%=test + 1>表达式</td><td><%=test + 1%></td></tr>
<%if (true) {%>
<tr><td>if</td><td>if 语句</td></tr>
<%}%>
<%}%>
</table>
</script>
<script src="../template.js"></script>
<script>
var tpl = document.getElementById('tpl').innerHTML;
var startTime = (new Date).getTime();
var count = 100000;
var i = count;
while(i--) {
template(tpl);
}
var endTime = (new Date).getTime();
var time = (endTime - startTime);
var averTime = time/count;
document.getElementById('wp').innerHTML = '共 ' + count + '次, 总时间 ' + time + 'ms, 平均 ' + averTime + 'ms/次';
</script>
</body>
</html>