"use strict"; const net = require("net"); const port = 4000; var time, times = []; function now() { let hrtime = process.hrtime(); return hrtime[0] * 1e9 + hrtime[1]; } net.createServer(function(socket) { let i = 0; socket.setNoDelay(true); time = now(); while (++i <= 80) { socket.write("."); } }).listen(port); setInterval(function() { let socket = new net.Socket(); socket.on("data", function (data) { console.log(data.toString()); times.push(Math.round((now() - time) / 1000)); socket.end(); }).connect(port); }, 100); process.on("SIGINT", function () { console.log("\n" + times.length + " data events, average delay: " + Math.round(times.reduce(function (a, b) { return a + b; }) / times.length) + "µs"); process.exit(); });