-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwpbench.html
123 lines (114 loc) · 3.99 KB
/
wpbench.html
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<title>wpbench</title>
<script>
function absurl(doc, href) {
var a = doc.createElement("a");
a.href = href;
return a.href;
}
function cssIsReady(doc, href) {
var i, sheets = doc.styleSheets;
for (i = 0; i != sheets.length; ++i) {
if (sheets[i].href == href)
return true;
}
return false;
}
function getStyleRefs(doc) {
var refs = [];
var nodesInHead = doc.head.childNodes;
for (var i = 0; i != nodesInHead.length; ++i) {
var node = nodesInHead[i];
if (node.nodeType != 1)
continue;
if (node.tagName.match(/^link$/i) == null)
continue;
if ((t = node.getAttribute("rel")) == null || t.match(/^\s*stylesheet\s*$/i) == null)
continue;
if ((t = node.getAttribute("media")) != null && t.match(/^\s*(all|screen)\s*$/i) == null)
continue;
if ((t = node.getAttribute("href")) == null)
continue;
refs.push(absurl(doc, t));
}
return refs;
}
function allCSSAreReady(doc, refs) {
for (var i = 0; i != refs.length; ++i) {
if (!cssIsReady(doc, refs[i]))
return false;
}
return true;
}
function start() {
var resultElement = document.getElementById("result");
var targetElement = document.getElementById("testframe");
if (targetElement.contentDocument.location != "about:blank") {
targetElement.contentDocument.location = "about:blank";
setTimeout(start, 100);
return;
}
resultElement.value = "";
var elapsed = (function () {
var start = new Date();
return function () {
return new Date() - start;
}
})();
var pollTimers = (function () {
var styleRefs = null;
var waitForCSS = function () {
if (styleRefs == null)
styleRefs = getStyleRefs(targetElement.contentDocument);
if (allCSSAreReady(targetElement.contentDocument, styleRefs)) {
resultElement.value += "css-loaded: " + elapsed() + " msec\n";
return;
}
setTimeout(waitForCSS, 10);
};
var waitForBody = function () {
if (targetElement.contentDocument.body != null) {
resultElement.value += "head-parsed: " + elapsed() + " msec\n";
if (navigator.userAgent.match(/Firefox\//) == null)
waitForCSS();
return;
}
setTimeout(waitForBody, 10);
};
return waitForBody;
})();
targetElement.contentWindow.addEventListener("unload", function () {
resultElement.value += "unload: " + elapsed() + " msec\n";
setTimeout(function () {
if (targetElement.contentDocument.location == "about:blank") {
alert("failed to wait until unload complete");
return;
}
pollTimers();
targetElement.contentWindow.addEventListener("DOMContentLoaded", function () {
resultElement.value += "DOMContentLoaded: " + elapsed() + " msec\n";
});
targetElement.contentWindow.addEventListener("load", function () {
resultElement.value += "load: " + elapsed() + " msec\n";
});
}, 0);
});
targetElement.contentDocument.location = document.getElementById("target-path").value;
}
</script>
<body>
<h1>wpbench - benchmark the load timings of a web page</h1>
<hr>
<table border=0>
<form onsubmit="start(); return false">
<tr><th align=right>Test URL Path:<td><input id="target-path" value="/" size=40>
<input type="submit" value="Start">
<tr><th align=right valign=top>Results:<td><textarea id="result" rows=5 cols=40></textarea>
</form>
</table>
<p>
The iframe below is used for loading the test page.<br>
Note: you may need to restart the server and the browser, clear the cache to obtain repetitive results.
<hr>
<iframe id="testframe" src="about:blank" width="80%" height="20%" border="1"></iframe>
<hr>
Copyright © 2015 Kazuho Oku