Created
January 13, 2015 00:16
-
-
Save tonymeng/23be07450ced63351e1f 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 = 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