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