Unreviewed. Add some WebGPU examples.
[WebKit-https.git] / Websites / webkit.org / perf / slickspeed / system / slickspeed.js
1 //base test functions
2
3 function forEach(iterable, fn, bind){
4         for (var i = 0, j = iterable.length; i < j; i++) fn.call(bind, iterable[i], i, iterable);
5 };
6
7 //test start
8
9 window.onload = function(){
10         
11         var frameworks = {};
12         
13         forEach(document.getElementsByTagName('iframe'), function(iframe){
14                 frameworks[iframe.name] = {
15                         'test': window.frames[iframe.name].test,
16                         'attribute': window.frames[iframe.name].modifier || '',
17                         'selectors': []
18                 };
19         });
20         
21         var tbody = document.getElementById('tbody');
22         var tfoot = document.getElementById('tfoot');
23         var lastrow = tfoot.getElementsByTagName('tr')[0];
24         
25         var controls = document.getElementById('controls');
26         
27         var links = controls.getElementsByTagName('a');
28         
29         var start = links[1];
30         var stop = links[0];
31         
32         start.onclick = function(){
33                 testRunner();
34                 return false;
35         };
36         
37         stop.onclick = function(){
38                 clearTimeout(timer);
39                 timer = null;
40                 return false;
41         };
42         
43         var score = [];
44         var scores = {};
45         
46         var frxi = 0;
47         for (var name in frameworks){
48                 var framework = frameworks[name];
49                 forEach(window.selectors, function(selector){
50                         var frameworkSelector = selector.replace('%', frameworks[name].attribute);
51                         framework.selectors.push(frameworkSelector);
52                 });
53                 scores[name] = lastrow.getElementsByTagName('td')[frxi];
54                 score[name] = 0;
55                 frxi++;
56         }
57         
58         var tests = [];
59
60         forEach(window.selectors, function(selector, i){
61                 var frxi = 0;
62                 var row = tbody.getElementsByTagName('tr')[i];
63                 for (var name in frameworks){
64                         var framework = frameworks[name];
65                         var cell = row.getElementsByTagName('td')[frxi];
66                         tests.push({
67                                 'execute': framework.test,
68                                 'selector': framework.selectors[i],
69                                 'name': name,
70                                 'row': row,
71                                 'cell' : cell
72                         });
73                         frxi++;
74                 }
75         });
76         
77         var timer = null;
78         
79         var testRunner = function(){
80                 var test = tests.shift();
81                 if (!test) return;
82                 var results = test.execute(test.selector);
83                 test.cell.className = 'test';
84                 test.cell.innerHTML = results.time + ' ms | ' + results.found + ' found';
85                 test.cell.speed = results.time;
86                 if (results.found == 0){
87                         test.cell.innerHTML = results.time + ' ms | zero results';
88                         test.cell.className += ' zero';
89                         test.cell.found = 0;
90                         test.cell.error = true;
91                 } else if (results.error){
92                         test.cell.innerHTML = results.time + ' ms | <span class="exception" title="' + results.error + '">error returned</a>';
93                         test.cell.className += ' exception';
94                         test.cell.found = 0;
95                         test.cell.error = true;
96                 } else {
97                         test.cell.found = results.found;
98                         test.cell.error = false;
99                 }
100                 
101                 score[test.name] += test.cell.speed;
102                 scores[test.name].innerHTML =  '&nbsp;' + score[test.name] + '&nbsp;';
103                 
104                 if (test.cell == test.row.lastChild) colourRow(test.row);
105                 timer = setTimeout(testRunner, 0);
106         };
107         
108         var colourRow = function(row){
109                 
110                 var cells = [];
111                 
112                 var tds = row.getElementsByTagName('td');
113                 forEach(tds, function(td){
114                         cells.push(td);
115                 });
116                 
117                 var speeds = [];
118                 
119                 forEach(cells, function(cell, i){
120                         if (!cell.error) speeds[i] = cell.speed;
121                         //error, so we exclude it from colouring
122                         else speeds[i] = 99999999999999999999999;
123                 });
124                 
125                 var min = Math.min.apply(this, speeds);
126                 var max = Math.max.apply(this, speeds);
127                 
128                 var found = [];
129                 var mismatch = false;
130                 forEach(cells, function(cell, i){
131                         found.push(cell.found);
132                         if (!mismatch){
133                                 forEach(found, function(n){
134                                         if (cell.found && n && cell.found != n){
135                                                 mismatch = true;
136                                                 return;
137                                         }
138                                 });
139                         }
140                         if (cell.speed == min) cell.className += ' good';
141                         else if (cell.speed == max) cell.className += ' bad';
142                         else cell.className += ' normal';
143                 });
144                 
145                 if (mismatch){
146                         forEach(cells, function(cell, i){
147                                 if (cell.found) cell.className += ' mismatch';
148                         });
149                 }
150                 
151         };
152         
153
154 };