0da93cbaba302a012c670e2c7774ce103fc59342
[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, options)
10     {
11         Stage.prototype.initialize.call(this, benchmark, options);
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;
104
105         if (count > 0) {
106             for (var i = 0; i < count; ++i)
107                 this._pushTextElement();
108             return;
109         }
110
111         count = Math.min(-count, this._textElements.length);
112         for (var i = 0; i < count; ++i)
113             this._popTextElement();
114     },
115
116     complexity: function()
117     {
118         return this._textElements.length;
119     }
120 });
121
122 Utilities.extendObject(LayeringTextStage, {
123     textItems: [
124         "<div class='text-layer'>",
125             "<h2>Types of benchmarks</h2>",
126             "<ol>",
127                 "<li>Real program",
128                     "<ul>",
129                         "<li>word processing software</li>",
130                         "<li>tool software of CAD</li>",
131                         "<li>user's application software (i.e.: MIS)</li>",
132                     "</ul>",
133                 "</li>",
134                 "<li>Kernel",
135                     "<ul>",
136                         "<li>contains key codes</li>",
137                         "<li>normally abstracted from actual program</li>",
138                         "<li>popular kernel: Livermore loop</li>",
139                         "<li>linpack benchmark (contains basic linear algebra subroutine written in FORTRAN language)</li>",
140                         "<li>results are represented in MFLOPS</li>",
141                     "</ul>",
142                 "</li>",
143                 "<li>Synthetic Benchmark",
144                     "<ul>",
145                         "<li>Procedure for programming synthetic benchmark:",
146                             "<ul>",
147                                 "<li>take statistics of all types of operations from many application programs</li>",
148                                 "<li>get proportion of each operation</li>",
149                                 "<li>write program based on the proportion above</li>",
150                             "</ul>",
151                         "</li>",
152                         "<li>Types of Synthetic Benchmark are:",
153                             "<ul>",
154                                 "<li>Whetstone</li>",
155                                 "<li>Dhrystone</li>",
156                             "</ul>",
157                         "</li>",
158                         "<li>These were the first general purpose industry standard computer benchmarks. They do not necessarily obtain high scores on modern pipelined computers.</li>",
159                     "</ul>",
160                 "</li>",
161                 "<li>I/O benchmarks</li>",
162                 "<li>Database benchmarks: to measure the throughput and response times of database management systems (DBMS')</li>",
163                 "<li>Parallel benchmarks: used on machines with multiple cores, processors or systems consisting of multiple machines</li>",
164             "</ol>",
165             "<h2>Common benchmarks</h2>",
166             "<ul>",
167                 "<li>Business Applications Performance Corporation (BAPCo)</li>",
168                 "<li>Embedded Microprocessor Benchmark Consortium (EEMBC)</li>",
169                 "<li>Standard Performance Evaluation Corporation (SPEC), in particular their SPECint and SPECfp</li>",
170                 "<li>Transaction Processing Performance Council (TPC)</li>",
171                 "<li>Coremark: Embedded computing benchmark</li>",
172             "</ul>",
173             "<h3>Open source benchmarks</h3>",
174             "<ul>",
175                 "<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>",
176                 "<li>Bonnie++: filesystem and hard drive benchmark</li>",
177                 "<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>",
178             "</ul>",
179         "</div>"
180     ],
181
182     parseTextItem: function(textItem)
183     {
184         var parseResult = {};
185         parseResult.tagStart = textItem.match(/<(.*?)>/g)[0];
186         var spaceIndex = parseResult.tagStart.indexOf(" ");
187         parseResult.nodeName = parseResult.tagStart.substring(1, spaceIndex != -1 ? spaceIndex : parseResult.tagStart.length - 1);
188         parseResult.args = spaceIndex != -1 ? Utilities.parseArguments(parseResult.tagStart.substring(spaceIndex + 1, parseResult.tagStart.length - 1)) : {};
189         var tagEnd = "</" + parseResult.nodeName + ">";
190         parseResult.tagEnd = textItem.endsWith(tagEnd) ? tagEnd : "";
191         return parseResult;
192     },
193
194     isOpeningTextItem: function(textItem)
195     {
196         return !LayeringTextStage.parseTextItem(textItem).tagEnd.length;
197     },
198
199     isClosingTextItem: function(textItem)
200     {
201         return textItem.indexOf("/") == +1;
202     },
203
204     isColorableTextItem: function(textItemFlags)
205     {
206         return !(textItemFlags.isOpening || textItemFlags.isClosing);
207     },
208
209     isInsertableTextItem: function(textItemFlags)
210     {
211         return !textItemFlags.isClosing;
212     },
213
214     colorIndexToTextElementIndex: function(colorIndex)
215     {
216         var textElementIndex = 0;
217         var index = 0;
218
219         for (var textItemIndex = 0; textItemIndex < LayeringTextStage.textItemsFlags.length; ++textItemIndex) {
220             if (LayeringTextStage.isColorableTextItem(LayeringTextStage.textItemsFlags[textItemIndex])) {
221                 if (++index > colorIndex)
222                     break;
223             }
224             if (LayeringTextStage.isInsertableTextItem(LayeringTextStage.textItemsFlags[textItemIndex]))
225                 ++textElementIndex;
226         }
227
228         return textElementIndex;
229     }
230 });
231
232 Utilities.extendObject(LayeringTextStage, {
233     textItemsFlags: LayeringTextStage.textItems.map(function(textItem)
234     {
235        var textItemFlags = {};
236        textItemFlags.isOpening = LayeringTextStage.isOpeningTextItem(textItem);
237        textItemFlags.isClosing = LayeringTextStage.isClosingTextItem(textItem);
238        return textItemFlags;
239     })
240 });
241
242 Utilities.extendObject(LayeringTextStage, {
243     colorableTextItems: LayeringTextStage.textItemsFlags.filter(function(textItemFlags)
244     {
245         return LayeringTextStage.isColorableTextItem(textItemFlags);
246     }).length,
247
248     insertableTextItems: LayeringTextStage.textItemsFlags.filter(function(textItemFlags)
249     {
250         return LayeringTextStage.isInsertableTextItem(textItemFlags);
251     }).length
252 });
253
254 LayeringTextBenchmark = Utilities.createSubclass(Benchmark,
255     function(options)
256     {
257         Benchmark.call(this, new LayeringTextStage(), options);
258     }
259 );
260
261 window.benchmarkClass = LayeringTextBenchmark;
262
263 })();
264