Simplify the test harness
[WebKit-https.git] / PerformanceTests / Animometer / tests / text / resources / layering-text.js
1 (function() {
2
3 LayeringTextStage = Utilities.createSubclass(Stage,
4     function()
5     {
6         Stage.call(this);
7     }, {
8
9     initialize: function(benchmark)
10     {
11         Stage.prototype.initialize.call(this, benchmark);
12         this._textElementParent = this.element;
13         this._textElements = [];
14         this._textItemIndex = 0;
15         this._colorIndex = 0;
16         this._animateCounts = 0;
17     },
18
19     _nextTextItem: function(textItemFlags)
20     {
21         var textItem = LayeringTextStage.textItems[this._textItemIndex];
22         Utilities.extendObject(textItemFlags, LayeringTextStage.textItemsFlags[this._textItemIndex]);
23         this._textItemIndex = (this._textItemIndex + 1) % LayeringTextStage.textItems.length;
24         return textItem;
25     },
26
27     _previousTextItem: function(textItemFlags)
28     {
29         this._textItemIndex = (this._textItemIndex + LayeringTextStage.textItems.length - 1) % LayeringTextStage.textItems.length;
30         Utilities.extendObject(textItemFlags, LayeringTextStage.textItemsFlags[this._textItemIndex]);
31         return LayeringTextStage.textItems[this._textItemIndex];
32     },
33
34     _pushTextElement: function()
35     {
36         var textItemFlags = {};
37         var textItem = this._nextTextItem(textItemFlags);
38         for ( ; textItemFlags.isClosing; textItem = this._nextTextItem(textItemFlags))
39             this._textElementParent = this._textElementParent.parentNode;
40
41         var parseResult = LayeringTextStage.parseTextItem(textItem);
42         textItem = textItem.substring(parseResult.tagStart.length, textItem.length - parseResult.tagEnd.length);
43
44         var textElement = document.createElement(parseResult.nodeName);
45
46         for (var attrname in parseResult.args)
47             textElement.setAttribute(attrname, parseResult.args[attrname]);
48
49         this._textElementParent.appendChild(textElement);
50
51         if (!parseResult.tagEnd.length)
52             this._textElementParent = textElement;
53
54         textElement.innerHTML = textItem;
55
56         this._textElements.push(textElement);
57         return this._textElements.length;
58     },
59
60     _popTextElement: function()
61     {
62         var textItemFlags = {};
63         var textItem = this._previousTextItem(textItemFlags);
64         for ( ; textItemFlags.isClosing; textItem = this._previousTextItem(textItemFlags))
65             this._textElementParent = this._textElementParent.lastChild;
66
67         if (textItemFlags.isOpening)
68             this._textElementParent = this._textElementParent.parentNode;
69
70         this._textElements[this._textElements.length - 1].remove();
71
72         this._textElements.pop();
73         return this._textElements.length;
74     },
75
76     _colorTextItem: function(color)
77     {
78         var textElementIndex = LayeringTextStage.colorIndexToTextElementIndex(this._colorIndex);
79         for ( ; textElementIndex < this._textElements.length; textElementIndex += LayeringTextStage.insertableTextItems)
80             this._textElements[textElementIndex].style.backgroundColor = color;
81     },
82
83     animate: function(timeDelta)
84     {
85         this._colorTextItem("transparent");
86         this._colorIndex = (this._colorIndex + 1) % LayeringTextStage.colorableTextItems;
87         this._colorTextItem("YellowGreen");
88
89         var blackTextElements = Math.min(this._textElements.length, LayeringTextStage.insertableTextItems);
90         var i = 0;
91         for ( ; i < this._textElements.length - blackTextElements; ++i)
92             this._textElements[i].style.color = (this._animateCounts & 1) ? "LightYellow" : "white";
93
94         for ( ; i < this._textElements.length; ++i)
95             this._textElements[i].style.color = "black";
96
97         ++this._animateCounts;
98     },
99
100     tune: function(count)
101     {
102         if (count == 0)
103             return this._textElements.length;
104
105         if (count > 0) {
106             for (var i = 0; i < count; ++i)
107                 this._pushTextElement();
108             return this._textElements.length;
109         }
110
111         count = Math.min(-count, this._textElements.length);
112         for (var i = 0; i < count; ++i)
113             this._popTextElement();
114
115         return this._textElements.length;
116     }
117 });
118
119 Utilities.extendObject(LayeringTextStage, {
120     textItems: [
121         "<div class='text-layer'>",
122             "<h2>Types of benchmarks</h2>",
123             "<ol>",
124                 "<li>Real program",
125                     "<ul>",
126                         "<li>word processing software</li>",
127                         "<li>tool software of CAD</li>",
128                         "<li>user's application software (i.e.: MIS)</li>",
129                     "</ul>",
130                 "</li>",
131                 "<li>Kernel",
132                     "<ul>",
133                         "<li>contains key codes</li>",
134                         "<li>normally abstracted from actual program</li>",
135                         "<li>popular kernel: Livermore loop</li>",
136                         "<li>linpack benchmark (contains basic linear algebra subroutine written in FORTRAN language)</li>",
137                         "<li>results are represented in MFLOPS</li>",
138                     "</ul>",
139                 "</li>",
140                 "<li>Synthetic Benchmark",
141                     "<ul>",
142                         "<li>Procedure for programming synthetic benchmark:",
143                             "<ul>",
144                                 "<li>take statistics of all types of operations from many application programs</li>",
145                                 "<li>get proportion of each operation</li>",
146                                 "<li>write program based on the proportion above</li>",
147                             "</ul>",
148                         "</li>",
149                         "<li>Types of Synthetic Benchmark are:",
150                             "<ul>",
151                                 "<li>Whetstone</li>",
152                                 "<li>Dhrystone</li>",
153                             "</ul>",
154                         "</li>",
155                         "<li>These were the first general purpose industry standard computer benchmarks. They do not necessarily obtain high scores on modern pipelined computers.</li>",
156                     "</ul>",
157                 "</li>",
158                 "<li>I/O benchmarks</li>",
159                 "<li>Database benchmarks: to measure the throughput and response times of database management systems (DBMS')</li>",
160                 "<li>Parallel benchmarks: used on machines with multiple cores, processors or systems consisting of multiple machines</li>",
161             "</ol>",
162             "<h2>Common benchmarks</h2>",
163             "<ul>",
164                 "<li>Business Applications Performance Corporation (BAPCo)</li>",
165                 "<li>Embedded Microprocessor Benchmark Consortium (EEMBC)</li>",
166                 "<li>Standard Performance Evaluation Corporation (SPEC), in particular their SPECint and SPECfp</li>",
167                 "<li>Transaction Processing Performance Council (TPC)</li>",
168                 "<li>Coremark: Embedded computing benchmark</li>",
169             "</ul>",
170             "<h3>Open source benchmarks</h3>",
171             "<ul>",
172                 "<li>AIM Multiuser Benchmark: composed of a list of tests that could be mixed to create a 'load mix' that would simulate a specific computer function on any UNIX-type OS.</li>",
173                 "<li>Bonnie++: filesystem and hard drive benchmark</li>",
174                 "<li>BRL-CAD: cross-platform architecture-agnostic benchmark suite based on multithreaded ray tracing performance; baselined against a VAX-11/780; and used since 1984 for evaluating relative CPU performance, compiler differences, optimization levels, coherency, architecture differences, and operating system differences.</li>",
175             "</ul>",
176         "</div>"
177     ],
178
179     parseTextItem: function(textItem)
180     {
181         var parseResult = {};
182         parseResult.tagStart = textItem.match(/<(.*?)>/g)[0];
183         var spaceIndex = parseResult.tagStart.indexOf(" ");
184         parseResult.nodeName = parseResult.tagStart.substring(1, spaceIndex != -1 ? spaceIndex : parseResult.tagStart.length - 1);
185         parseResult.args = spaceIndex != -1 ? Utilities.parseArguments(parseResult.tagStart.substring(spaceIndex + 1, parseResult.tagStart.length - 1)) : {};
186         var tagEnd = "</" + parseResult.nodeName + ">";
187         parseResult.tagEnd = textItem.endsWith(tagEnd) ? tagEnd : "";
188         return parseResult;
189     },
190
191     isOpeningTextItem: function(textItem)
192     {
193         return !LayeringTextStage.parseTextItem(textItem).tagEnd.length;
194     },
195
196     isClosingTextItem: function(textItem)
197     {
198         return textItem.indexOf("/") == +1;
199     },
200
201     isColorableTextItem: function(textItemFlags)
202     {
203         return !(textItemFlags.isOpening || textItemFlags.isClosing);
204     },
205
206     isInsertableTextItem: function(textItemFlags)
207     {
208         return !textItemFlags.isClosing;
209     },
210
211     colorIndexToTextElementIndex: function(colorIndex)
212     {
213         var textElementIndex = 0;
214         var index = 0;
215
216         for (var textItemIndex = 0; textItemIndex < LayeringTextStage.textItemsFlags.length; ++textItemIndex) {
217             if (LayeringTextStage.isColorableTextItem(LayeringTextStage.textItemsFlags[textItemIndex])) {
218                 if (++index > colorIndex)
219                     break;
220             }
221             if (LayeringTextStage.isInsertableTextItem(LayeringTextStage.textItemsFlags[textItemIndex]))
222                 ++textElementIndex;
223         }
224
225         return textElementIndex;
226     }
227 });
228
229 Utilities.extendObject(LayeringTextStage, {
230     textItemsFlags: LayeringTextStage.textItems.map(function(textItem)
231     {
232        var textItemFlags = {};
233        textItemFlags.isOpening = LayeringTextStage.isOpeningTextItem(textItem);
234        textItemFlags.isClosing = LayeringTextStage.isClosingTextItem(textItem);
235        return textItemFlags;
236     })
237 });
238
239 Utilities.extendObject(LayeringTextStage, {
240     colorableTextItems: LayeringTextStage.textItemsFlags.filter(function(textItemFlags)
241     {
242         return LayeringTextStage.isColorableTextItem(textItemFlags);
243     }).length,
244
245     insertableTextItems: LayeringTextStage.textItemsFlags.filter(function(textItemFlags)
246     {
247         return LayeringTextStage.isInsertableTextItem(textItemFlags);
248     }).length
249 });
250
251 LayeringTextBenchmark = Utilities.createSubclass(Benchmark,
252     function(options)
253     {
254         Benchmark.call(this, new LayeringTextStage(), options);
255     }
256 );
257
258 window.benchmarkClass = LayeringTextBenchmark;
259
260 })();
261