blob: 6177470ea400c76c7a088250d4de3a01fcfb150f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
<!DOCTYPE html>
<html>
<head>
<title>Chapter reflow performance test: random text</title>
<script src="../resources/runner.js"></script>
</head>
<body>
<pre id="log"></pre>
<div id="target" style="width: 300px; display: none;">
</div>
<script>
var RandomTextGenerator = function() {
this.letters = [
String.fromCharCode(RandomTextGenerator.firstCharCode),
String.fromCharCode(RandomTextGenerator.firstCharCode),
String.fromCharCode(RandomTextGenerator.firstCharCode),
String.fromCharCode(RandomTextGenerator.firstCharCode),
String.fromCharCode(RandomTextGenerator.firstCharCode),
String.fromCharCode(RandomTextGenerator.firstCharCode),
String.fromCharCode(RandomTextGenerator.firstCharCode),
String.fromCharCode(RandomTextGenerator.firstCharCode),
String.fromCharCode(RandomTextGenerator.firstCharCode),
String.fromCharCode(RandomTextGenerator.firstCharCode)
]
}
RandomTextGenerator.firstCharCode = 65; // 'A'
RandomTextGenerator.lastCharCode = 123; // 'z'
RandomTextGenerator.prototype.advance = function(index) {
var charCode = this.letters[index].charCodeAt(0);
var newCharCode = charCode + 1;
if (newCharCode > RandomTextGenerator.lastCharCode)
newCharCode = RandomTextGenerator.firstCharCode;
this.letters[index] = String.fromCharCode(newCharCode);
return charCode;
}
RandomTextGenerator.prototype.generate = function() {
var result = this.letters.join("");
var index = 0;
while (1) {
var charCode = this.advance(index);
if (charCode != RandomTextGenerator.lastCharCode)
break;
++index;
}
return result;
}
var target = document.getElementById("target");
var style = target.style;
var randomTextGenerator = new RandomTextGenerator;
function test() {
var target = document.getElementById("target");
var style = target.style;
var innerHTML = "<p>";
for (var i = 0; i < 5000; ++i)
innerHTML += randomTextGenerator.generate() + " ";
innerHTML += "</p>";
target.innerHTML = innerHTML;
style.display = "block";
style.width = "280px";
PerfTestRunner.forceLayoutOrFullFrame();
style.display = "none";
}
PerfTestRunner.measureRunsPerSecond({
description: "Measures performance of 3 layouts (using 2 different font-sizes) on a page containing random text.",
run: test
});
</script>
</body>
</html>
|