4 <title>Chapter reflow performance test: random text
</title>
5 <script src=
"../resources/runner.js"></script>
9 <div id=
"target" style=
"width: 300px; display: none;">
13 var RandomTextGenerator = function() {
15 String
.fromCharCode(RandomTextGenerator
.firstCharCode
),
16 String
.fromCharCode(RandomTextGenerator
.firstCharCode
),
17 String
.fromCharCode(RandomTextGenerator
.firstCharCode
),
18 String
.fromCharCode(RandomTextGenerator
.firstCharCode
),
19 String
.fromCharCode(RandomTextGenerator
.firstCharCode
),
20 String
.fromCharCode(RandomTextGenerator
.firstCharCode
),
21 String
.fromCharCode(RandomTextGenerator
.firstCharCode
),
22 String
.fromCharCode(RandomTextGenerator
.firstCharCode
),
23 String
.fromCharCode(RandomTextGenerator
.firstCharCode
),
24 String
.fromCharCode(RandomTextGenerator
.firstCharCode
)
28 RandomTextGenerator
.firstCharCode
= 65; // 'A'
30 RandomTextGenerator
.lastCharCode
= 123; // 'z'
32 RandomTextGenerator
.prototype.advance = function(index
) {
33 var charCode
= this.letters
[index
].charCodeAt(0);
34 var newCharCode
= charCode
+ 1;
35 if (newCharCode
> RandomTextGenerator
.lastCharCode
)
36 newCharCode
= RandomTextGenerator
.firstCharCode
;
37 this.letters
[index
] = String
.fromCharCode(newCharCode
);
41 RandomTextGenerator
.prototype.generate = function() {
42 var result
= this.letters
.join("");
46 var charCode
= this.advance(index
);
47 if (charCode
!= RandomTextGenerator
.lastCharCode
)
55 var target
= document
.getElementById("target");
56 var style
= target
.style
;
57 var randomTextGenerator
= new RandomTextGenerator
;
60 var target
= document
.getElementById("target");
61 var style
= target
.style
;
63 var innerHTML
= "<p>";
64 for (var i
= 0; i
< 5000; ++i
)
65 innerHTML
+= randomTextGenerator
.generate() + " ";
67 target
.innerHTML
= innerHTML
;
69 style
.display
= "block";
70 style
.width
= "280px";
71 PerfTestRunner
.forceLayoutOrFullFrame();
72 style
.display
= "none";
75 PerfTestRunner
.measureRunsPerSecond({
76 description
: "Measures performance of 3 layouts (using 2 different font-sizes) on a page containing random text.",