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 = 115000;
var q = async.queue(function (task, cb) {
var buf = new Buffer(task.name.toString());
var startTime = new Date().getTime();
client.send(buf, 0, buf.length, 7125, '127.0.0.1', function () {
totalTimeTaken += (new Date().getTime() - startTime);
cb();
});
}, 1000);
var tasks = [];
for (var i = 0; i < iterations; i+= 1) {
tasks.push({ name : i });
}
var actualTime = new Date().getTime();
q.drain = function () {
console.log('Iterations: ' + iterations + ', Average Time Taken: ' + (totalTimeTaken/iterations) + ', Total CPU Time: ' + totalTimeTaken + ', Actual Time: ' + (new Date().getTime() - actualTime));
process.exit(0);
}
q.push(tasks);
/* on my local machine, the following is what I see...
* Iterations: 112000, Average Time Taken: 3.3791160714285713, Total CPU Time: 378461, Actual Time: 1367
* Iterations: 112500, Average Time Taken: 4.8148888888888886, Total CPU Time: 541675, Actual Time: 1936
* Iterations: 113000, Average Time Taken: 3.389513274336283, Total CPU Time: 383015, Actual Time: 1389
* Iterations: 114000, Average Time Taken: 3.3979298245614036, Total CPU Time: 387364, Actual Time: 1418
* Iterations: 115000, Average Time Taken: 114.09519130434782, Total CPU Time: 13120947, Actual Time: 51417
*/
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.