-
-
Save tjfontaine/cdfe234e473e1468d824 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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