Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var async = require('async'),
dgram = require('dgram');
var client = dgram.createSocket('udp4');
var totalTimeTaken = 0;
var iterations = +process.argv[2];
var completed = 0;
console.log('doing', iterations, 'iterations');
var q = async.queue(function (task, cb) {
var buf = new Buffer(task.name.toString());
var startTime = Date.now();
client.send(buf, 0, buf.length, 7125, '127.0.0.1', function () {
totalTimeTaken += (Date.now() - startTime);
completed += 1;
cb();
});
}, 1000);
function chunk(count) {
var tasks = [];
for (var i = completed; i < count + completed; i+= 1) {
tasks.push({ name : i });
}
q.push(tasks);
}
var actualTime = new Date().getTime();
q.drain = function () {
console.log('Iterations:', completed,
', Average Time Taken:', (totalTimeTaken/completed),
', Total CPU Time: ', totalTimeTaken,
', Actual Time: ', (Date.now() - actualTime));
if (completed >= iterations)
process.exit(0);
chunk(1e4);
}
chunk(1e4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.