OLD | NEW |
| (Empty) |
1 #library("dom-traverse.dart"); | |
2 #import("dart:dom"); | |
3 #import('../../common/common.dart'); | |
4 #import('runner.dart'); | |
5 | |
6 | |
7 void main() { | |
8 final int num = 40; | |
9 | |
10 // Try to force real results. | |
11 var ret; | |
12 | |
13 String html = document.body.innerHTML; | |
14 | |
15 new Suite(window, 'dom-traverse') | |
16 .prep(() { | |
17 html = BenchUtil.replaceAll(html, 'id="test(\\w).*?"', (Match match) { | |
18 final group = match.group(1); | |
19 return 'id="test${group}${num}"'; | |
20 }); | |
21 html = BenchUtil.replaceAll(html, 'name="test.*?"', (Match match) { | |
22 return 'name="test${num}"'; | |
23 }); | |
24 html = BenchUtil.replaceAll(html, 'class="foo.*?"', (Match match) { | |
25 return 'class="foo test${num} bar"'; | |
26 }); | |
27 | |
28 final div = document.createElement('div'); | |
29 div.innerHTML = html; | |
30 document.body.appendChild(div); | |
31 }) | |
32 .test('firstChild', () { | |
33 final nodes = document.body.childNodes; | |
34 final nl = nodes.length; | |
35 | |
36 for (int i = 0; i < num; i++) { | |
37 for (int j = 0; j < nl; j++) { | |
38 Node cur = nodes[j]; | |
39 while (cur !== null) { | |
40 cur = cur.firstChild; | |
41 } | |
42 ret = cur; | |
43 } | |
44 } | |
45 }) | |
46 .test('lastChild', () { | |
47 final nodes = document.body.childNodes; | |
48 final nl = nodes.length; | |
49 | |
50 for (int i = 0; i < num; i++) { | |
51 for (int j = 0; j < nl; j++) { | |
52 Node cur = nodes[j]; | |
53 while (cur !== null) { | |
54 cur = cur.lastChild; | |
55 } | |
56 ret = cur; | |
57 } | |
58 } | |
59 }) | |
60 .test('nextSibling', () { | |
61 for (int i = 0; i < num * 2; i++) { | |
62 Node cur = document.body.firstChild; | |
63 while (cur !== null) { | |
64 cur = cur.nextSibling; | |
65 } | |
66 ret = cur; | |
67 } | |
68 }) | |
69 .test('previousSibling', () { | |
70 for (int i = 0; i < num * 2; i++) { | |
71 Node cur = document.body.firstChild; | |
72 while (cur !== null) { | |
73 cur = cur.previousSibling; | |
74 } | |
75 ret = cur; | |
76 } | |
77 }) | |
78 .test('childNodes', () { | |
79 for (int i = 0; i < num; i++) { | |
80 final nodes = document.body.childNodes; | |
81 for (int j = 0; j < nodes.length; j++) { | |
82 ret = nodes[j]; | |
83 } | |
84 } | |
85 }) | |
86 .end(); | |
87 } | |
OLD | NEW |