OLD | NEW |
| (Empty) |
1 class Main { | |
2 static void main() { | |
3 final int num = 40; | |
4 | |
5 // Try to force real results. | |
6 var ret; | |
7 window.on.load.add((Event evt) { | |
8 String html = document.body.innerHTML; | |
9 | |
10 new Suite('dom-query') | |
11 .prep(() { | |
12 html = BenchUtil.replaceAll(html, 'id="test(\\w).*?"', (Match match) { | |
13 final group = match.group(1); | |
14 return 'id="test${group}${num}"'; | |
15 }); | |
16 html = BenchUtil.replaceAll(html, 'name="test.*?"', (Match match) { | |
17 return 'name="test${num}"'; | |
18 }); | |
19 html = BenchUtil.replaceAll(html, 'class="foo.*?"', (Match match) { | |
20 return 'class="foo test${num} bar"'; | |
21 }); | |
22 final div = new Element.tag('div'); | |
23 div.innerHTML = html; | |
24 document.body.nodes.add(div); | |
25 }) | |
26 .test('getElementById', () { | |
27 for (int i = 0; i < num * 30; i++) { | |
28 ret = document.query('#testA' + num).tagName; | |
29 ret = document.query('#testB' + num).tagName; | |
30 ret = document.query('#testC' + num).tagName; | |
31 ret = document.query('#testD' + num).tagName; | |
32 ret = document.query('#testE' + num).tagName; | |
33 ret = document.query('#testF' + num).tagName; | |
34 } | |
35 }) | |
36 .test('getElementById (not in document)', () { | |
37 for (int i = 0; i < num * 30; i++) { | |
38 ret = document.query('#testA'); | |
39 ret = document.query('#testB'); | |
40 ret = document.query('#testC'); | |
41 ret = document.query('#testD'); | |
42 ret = document.query('#testE'); | |
43 ret = document.query('#testF'); | |
44 } | |
45 }) | |
46 .test('getElementsByTagName(div)', () { | |
47 for (int i = 0; i < num; i++) { | |
48 var elems = document.queryAll('div'); | |
49 ret = elems[elems.length-1].nodeType; | |
50 } | |
51 }) | |
52 .test('getElementsByTagName(p)', () { | |
53 for (int i = 0; i < num; i++) { | |
54 final elems = document.queryAll('p'); | |
55 ret = elems[elems.length-1].nodeType; | |
56 } | |
57 }) | |
58 .test('getElementsByTagName(a)', () { | |
59 for (int i = 0; i < num; i++) { | |
60 var elems = document.queryAll('a'); | |
61 ret = elems[elems.length-1].nodeType; | |
62 } | |
63 }) | |
64 .test('getElementsByTagName(*)', () { | |
65 for (int i = 0; i < num; i++) { | |
66 var elems = document.queryAll('*'); | |
67 ret = elems[elems.length-1].nodeType; | |
68 } | |
69 }) | |
70 .test('getElementsByTagName (not in document)', () { | |
71 for (int i = 0; i < num; i++) { | |
72 var elems = document.queryAll('strong'); | |
73 ret = elems.length == 0; | |
74 } | |
75 }) | |
76 .test('getElementsByName', () { | |
77 for (int i = 0; i < num * 20; i++) { | |
78 var elems = document.queryAll('[name=test$num]'); | |
79 ret = elems[elems.length-1].nodeType; | |
80 elems = document.queryAll('[name=test$num]'); | |
81 ret = elems[elems.length-1].nodeType; | |
82 elems = document.queryAll('[name=test$num]'); | |
83 ret = elems[elems.length-1].nodeType; | |
84 elems = document.queryAll('[name=test$num]'); | |
85 ret = elems[elems.length-1].nodeType; | |
86 } | |
87 }) | |
88 .test('getElementsByName (not in document)', () { | |
89 for (int i = 0; i < num * 20; i++) { | |
90 ret = document.queryAll('[name=test]').length == 0; | |
91 ret = document.queryAll('[name=test]').length == 0; | |
92 ret = document.queryAll('[name=test]').length == 0; | |
93 ret = document.queryAll('[name=test]').length == 0; | |
94 ret = document.queryAll('[name=test]').length == 0; | |
95 } | |
96 }) | |
97 .end(); | |
98 }); | |
99 } | |
100 } | |
101 | |
OLD | NEW |