Add benchmarking page.

This commit is contained in:
James Coglan
2011-12-16 21:11:23 +00:00
parent 918f86f58d
commit 0ea03585f9
+41
View File
@@ -0,0 +1,41 @@
<!doctype html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>WebSocket benchmarks</title>
</head>
<body>
<div id="out"></div>
<script type="text/javascript">
var Socket = window.MozWebSocket || window.WebSocket,
socket = new Socket('ws://' + location.hostname + ':' + location.port + '/'),
out = document.getElementById('out');
var msg = '', n = 64000;
while (n--) msg += 'X';
var start = new Date().getTime();
function ping(event) {
var data = (event && event.data) || '0',
id = parseInt(data.split(':')[0]) + 1;
out.innerHTML = id;
if (id === 1000) {
var time = new Date().getTime() - start;
out.innerHTML = 'Time: ' + time;
} else {
socket.send(id + ':' + msg);
}
};
socket.onopen = ping;
socket.onmessage = ping;
</script>
</body>
</html>