Skip to content

Instantly share code, notes, and snippets.

@tjfontaine
Forked from tonymeng/gist:23be07450ced63351e1f
Last active August 29, 2015 14:13
Show Gist options
  • Save tjfontaine/cdfe234e473e1468d824 to your computer and use it in GitHub Desktop.
Save tjfontaine/cdfe234e473e1468d824 to your computer and use it in GitHub Desktop.
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