Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: samples/third_party/dromaeo/tests/dom-query-html.dart

Issue 9732019: dart:html perf optimization based on runing Dromaeo benchmarks (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixes Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #library("dom_query_html"); 1 #library("dom_query");
2 #import("dart:html"); 2 #import("dart:html");
3 #import('../common/common.dart'); 3 #import('../common/common.dart');
4 #source("Common.dart"); 4 #import('runner.dart');
5 #source("RunnerSuite.dart");
6 5
7 void main() { 6 void main() {
8 final int num = 40; 7 final int num = 40;
9 8
10 // Try to force real results. 9 // Try to force real results.
11 var ret; 10 var ret;
12 11
13 String html = document.body.innerHTML; 12 String html = document.body.innerHTML;
14 13
15 new Suite(window, 'dom-query') 14 new Suite(window, 'dom-query')
16 .prep(() { 15 .prep(() {
17 html = BenchUtil.replaceAll(html, 'id="test(\\w).*?"', (Match match) { 16 html = BenchUtil.replaceAll(html, 'id="test(\\w).*?"', (Match match) {
18 final group = match.group(1); 17 final group = match.group(1);
19 return 'id="test${group}${num}"'; 18 return 'id="test${group}${num}"';
20 }); 19 });
21 html = BenchUtil.replaceAll(html, 'name="test.*?"', (Match match) { 20 html = BenchUtil.replaceAll(html, 'name="test.*?"', (Match match) {
22 return 'name="test${num}"'; 21 return 'name="test${num}"';
23 }); 22 });
24 html = BenchUtil.replaceAll(html, 'class="foo.*?"', (Match match) { 23 html = BenchUtil.replaceAll(html, 'class="foo.*?"', (Match match) {
25 return 'class="foo test${num} bar"'; 24 return 'class="foo test${num} bar"';
26 }); 25 });
27 final div = new Element.tag('div'); 26 final div = new Element.tag('div');
28 div.innerHTML = html; 27 div.innerHTML = html;
29 document.body.nodes.add(div); 28 document.body.$dom_appendChild(div);
30 }) 29 })
31 .test('getElementById', () { 30 .test('getElementById', () {
32 for (int i = 0; i < num * 30; i++) { 31 for (int i = 0; i < num * 30; i++) {
33 ret = document.query('#testA$num').hidden; 32 ret = document.$dom_getElementById('testA$num').$dom_nodeType;
34 ret = document.query('#testB$num').hidden; 33 ret = document.$dom_getElementById('testB$num').$dom_nodeType;
35 ret = document.query('#testC$num').hidden; 34 ret = document.$dom_getElementById('testC$num').$dom_nodeType;
36 ret = document.query('#testD$num').hidden; 35 ret = document.$dom_getElementById('testD$num').$dom_nodeType;
37 ret = document.query('#testE$num').hidden; 36 ret = document.$dom_getElementById('testE$num').$dom_nodeType;
38 ret = document.query('#testF$num').hidden; 37 ret = document.$dom_getElementById('testF$num').$dom_nodeType;
39 } 38 }
40 }) 39 })
41 .test('getElementById (not in document)', () { 40 .test('getElementById (not in document)', () {
42 for (int i = 0; i < num * 30; i++) { 41 for (int i = 0; i < num * 30; i++) {
43 ret = document.query('#testA'); 42 ret = document.$dom_getElementById('testA');
44 ret = document.query('#testB'); 43 ret = document.$dom_getElementById('testB');
45 ret = document.query('#testC'); 44 ret = document.$dom_getElementById('testC');
46 ret = document.query('#testD'); 45 ret = document.$dom_getElementById('testD');
47 ret = document.query('#testE'); 46 ret = document.$dom_getElementById('testE');
48 ret = document.query('#testF'); 47 ret = document.$dom_getElementById('testF');
49 } 48 }
50 }) 49 })
51 .test('getElementsByTagName(div)', () { 50 .test('getElementsByTagName(div)', () {
52 for (int i = 0; i < num; i++) { 51 for (int i = 0; i < num; i++) {
53 var elems = document.queryAll('div'); 52 final elems = document.$dom_getElementsByTagName('div');
54 ret = elems.last().hidden; 53 ret = elems.last().$dom_nodeType;
55 } 54 }
56 }) 55 })
57 .test('getElementsByTagName(p)', () { 56 .test('getElementsByTagName(p)', () {
58 for (int i = 0; i < num; i++) { 57 for (int i = 0; i < num; i++) {
59 final elems = document.queryAll('p'); 58 final elems = document.$dom_getElementsByTagName('p');
60 ret = elems.last().hidden; 59 ret = elems.last().$dom_nodeType;
61 } 60 }
62 }) 61 })
63 .test('getElementsByTagName(a)', () { 62 .test('getElementsByTagName(a)', () {
64 for (int i = 0; i < num; i++) { 63 for (int i = 0; i < num; i++) {
65 var elems = document.queryAll('a'); 64 final elems = document.$dom_getElementsByTagName('a');
66 ret = elems.last().hidden; 65 ret = elems.last().$dom_nodeType;
67 } 66 }
68 }) 67 })
69 .test('getElementsByTagName(*)', () { 68 .test('getElementsByTagName(*)', () {
70 for (int i = 0; i < num; i++) { 69 for (int i = 0; i < num; i++) {
71 var elems = document.queryAll('*'); 70 var elems = document.$dom_getElementsByTagName('*');
72 ret = elems.last().hidden; 71 ret = elems.last().$dom_nodeType;
73 } 72 }
74 }) 73 })
75 .test('getElementsByTagName (not in document)', () { 74 .test('getElementsByTagName (not in document)', () {
76 for (int i = 0; i < num; i++) { 75 for (int i = 0; i < num; i++) {
77 var elems = document.queryAll('strong'); 76 final elems = document.$dom_getElementsByTagName('strong');
78 ret = elems.length == 0; 77 ret = elems.last().$dom_nodeType;
79 } 78 }
80 }) 79 })
81 .test('getElementsByName', () { 80 .test('getElementsByName', () {
82 for (int i = 0; i < num * 20; i++) { 81 for (int i = 0; i < num * 20; i++) {
83 var elems = document.queryAll('[name="test$num"]'); 82 ElementList elems = document.$dom_getElementsByName('test$num');
84 ret = elems.last().hidden; 83 ret = elems[elems.length-1].$dom_nodeType;
85 elems = document.queryAll('[name="test$num"]'); 84 elems = document.$dom_getElementsByName('test$num');
86 ret = elems.last().hidden; 85 ret = elems[elems.length-1].$dom_nodeType;
87 elems = document.queryAll('[name="test$num"]'); 86 elems = document.$dom_getElementsByName('test$num');
88 ret = elems.last().hidden; 87 ret = elems[elems.length-1].$dom_nodeType;
89 elems = document.queryAll('[name="test$num"]'); 88 elems = document.$dom_getElementsByName('test$num');
90 ret = elems.last().hidden; 89 ret = elems[elems.length-1].$dom_nodeType;
91 } 90 }
92 }) 91 })
93 .test('getElementsByName (not in document)', () { 92 .test('getElementsByName (not in document)', () {
94 for (int i = 0; i < num * 20; i++) { 93 for (int i = 0; i < num * 20; i++) {
95 ret = document.queryAll('[name="test"]').length == 0; 94 ret = document.$dom_getElementsByName('test').length == 0;
96 ret = document.queryAll('[name="test"]').length == 0; 95 ret = document.$dom_getElementsByName('test').length == 0;
97 ret = document.queryAll('[name="test"]').length == 0; 96 ret = document.$dom_getElementsByName('test').length == 0;
98 ret = document.queryAll('[name="test"]').length == 0; 97 ret = document.$dom_getElementsByName('test').length == 0;
99 ret = document.queryAll('[name="test"]').length == 0; 98 ret = document.$dom_getElementsByName('test').length == 0;
100 } 99 }
101 }) 100 })
102 .end(); 101 .end();
103 } 102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698