This repository has been archived by the owner on Jul 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.html
61 lines (56 loc) · 1.72 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Shadow world test</title>
<script src="/socket.io/socket.io.js"></script>
<script>
var received_amount = 0;
var messages, start;
var updater;
var socket = new io.Socket('localhost');
socket.connect();
socket.on('connect', function() {
// console.log("Connected");
})
socket.on('message', function(){
received_amount++;
if (received_amount >= messages) {
clearInterval(updater);
update_result();
}
})
socket.on('disconnect', function(){
// console.log("Disconnected");
})
function update_result() {
var result;
if (!result) {
result = document.getElementById('result')
}
result.innerHTML = "Received " + received_amount + " messages in " + (new Date().getTime() - start) + "ms";
}
function stress() {
received_amount = 0;
updater = setInterval(function() {
if (received_amount > 0) {
update_result();
}
}, 1000);
messages = parseInt(document.getElementById('messages').value);
start = new Date().getTime();
for (var i=0; i < messages; i++) {
socket.send("PING");
};
document.getElementById('sent').innerHTML = "Sent " + messages + " messages in " + (new Date().getTime() - start) + "ms";
}
</script>
</head>
<body>
# of messages to send: <input type="text" id="messages" value="10000">
<button onclick="stress();">Stress</button>
<div id="sent"></div>
<div id="received"></div>
<div id="result"></div>
</body>
</html>