Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Add throughput benchmark
  • Loading branch information
ry committed Oct 12, 2011
1 parent f164704 commit 2b46959
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
25 changes: 25 additions & 0 deletions benchmark/throughput-child.js
@@ -0,0 +1,25 @@
var net = require('net');
var received = 0;
var start = new Date();
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.
var now = new Date();
var gigabytes = received / (1024 * 1024 * 1024);
var gigabits = gigabytes * 8.0;
var millisec = now - start;
var sec = millisec / 1000;
console.log((gigabits / sec) + " gbit/sec")
}
}, 1000);
21 changes: 21 additions & 0 deletions benchmark/throughput.js
@@ -0,0 +1,21 @@
var fork = require('child_process').fork;
var net = require('net');
var buffer = new Buffer(1024 * 1024);

function write(socket) {
if (!socket.writable) return;

socket.write(buffer, function() {
write(socket);
});
}

var server = net.createServer(function(socket) {
server.close();
write(socket);
});

server.listen(8000, function() {
fork(__dirname + '/throughput-child.js');
});

0 comments on commit 2b46959

Please sign in to comment.