From 7c81a98632c4a817418f1e17635ef40cf2e15def Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Sun, 2 Aug 2020 14:21:11 -0700 Subject: [PATCH] Add a node.js benchmarking test program, to see how fast node can receive messages. --- test/compatibility/node/devnull_client.js | 42 +++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/compatibility/node/devnull_client.js diff --git a/test/compatibility/node/devnull_client.js b/test/compatibility/node/devnull_client.js new file mode 100644 index 00000000..a65b493a --- /dev/null +++ b/test/compatibility/node/devnull_client.js @@ -0,0 +1,42 @@ +// +// With ws@7.3.1 +// and +// node --version +// v13.11.0 +// +// In a different terminal, start a push server: +// $ ws push_server -q +// +// $ node devnull_client.js +// messages received per second: 16643 +// messages received per second: 28065 +// messages received per second: 28432 +// messages received per second: 22207 +// messages received per second: 28805 +// messages received per second: 28694 +// messages received per second: 28180 +// messages received per second: 28601 +// messages received per second: 28698 +// messages received per second: 28931 +// messages received per second: 27975 +// +const WebSocket = require('ws'); + +const ws = new WebSocket('ws://localhost:8008'); + +ws.on('open', function open() { + ws.send('hello from node'); +}); + +var receivedMessages = 0; + +setInterval(function timeout() { + console.log(`messages received per second: ${receivedMessages}`) + receivedMessages = 0; +}, 1000); + +ws.on('message', function incoming(data) { + receivedMessages += 1; +}); + +