2011-10-12 07:40:04 +02:00
|
|
|
var net = require('net');
|
|
|
|
var received = 0;
|
2012-11-11 19:02:33 +01:00
|
|
|
var start = process.hrtime();
|
2011-10-12 07:40:04 +02:00
|
|
|
var socket = net.connect(8000);
|
|
|
|
|
|
|
|
socket.on('data', function(d) {
|
|
|
|
received += d.length;
|
|
|
|
});
|
|
|
|
|
|
|
|
var interval = setInterval(function() {
|
|
|
|
// After 1 gigabyte shutdown.
|
|
|
|
if (received > 10 * 1024 * 1024 * 1024) {
|
|
|
|
socket.destroy();
|
|
|
|
clearInterval(interval);
|
|
|
|
process.exit(0);
|
|
|
|
} else {
|
|
|
|
// Otherwise print some stats.
|
2012-11-11 19:02:33 +01:00
|
|
|
var elapsed = process.hrtime(start);
|
|
|
|
var sec = elapsed[0] + elapsed[1]/1E9;
|
2011-10-12 07:40:04 +02:00
|
|
|
var gigabytes = received / (1024 * 1024 * 1024);
|
|
|
|
var gigabits = gigabytes * 8.0;
|
|
|
|
console.log((gigabits / sec) + " gbit/sec")
|
|
|
|
}
|
|
|
|
}, 1000);
|