Skip to content

Commit

Permalink
allow benchmark to select which library to use
Browse files Browse the repository at this point in the history
  • Loading branch information
tjfontaine committed Oct 9, 2012
1 parent 2bbbcb7 commit 12bad04
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 42 deletions.
94 changes: 52 additions & 42 deletions benchmark.js
@@ -1,11 +1,10 @@
var mine = require('./dns'); 'use strict';
var theirs = require('dns');
var assert = require('assert');
var EventEmitter = require('events').EventEmitter; var EventEmitter = require('events').EventEmitter;
var util = require('util'); var util = require('util');


mine.platform.cache = false; /*
/* XXX XXX XXX I guess if you want to make it fair disable caching
Does ramping up "concurrency" test our ability to keep track of Does ramping up "concurrency" test our ability to keep track of
multiple queries in flight, or does it just benchmark process.nextTick? multiple queries in flight, or does it just benchmark process.nextTick?
Expand Down Expand Up @@ -66,9 +65,6 @@ native-dns 512 0.173 5780.346820809249
native-dns 1024 0.164 6097.560975609756 native-dns 1024 0.164 6097.560975609756
*/ */


var COUNT = 1000;
var CON = [ 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]

var names = [ var names = [
'www.google.com', 'www.google.com',
'www.facebook.com', 'www.facebook.com',
Expand Down Expand Up @@ -102,7 +98,7 @@ var Bench = function(name, library, count, concurrency) {
util.inherits(Bench, EventEmitter); util.inherits(Bench, EventEmitter);


var nextTick = process.nextTick; var nextTick = process.nextTick;
//var nextTick = global.setImmediate || process.nextTick; var nextTick = global.setImmediate || process.nextTick;


Bench.prototype.start = function() { Bench.prototype.start = function() {
var i, self = this; var i, self = this;
Expand Down Expand Up @@ -160,43 +156,57 @@ Bench.prototype.end = function() {
this.emit('end'); this.emit('end');
}; };


var con = CON.pop(); var opt = require('optimist').usage('Usage: $0 <library> <concurrency> <queries>');

var argv = opt.argv._;
var nextIter = function() {
if (!con) { if (argv.length != 3) {
end(); opt.showHelp()
return; process.exit(1)
} }


var a = new Bench('stock', theirs, COUNT, con); var library_name = argv[0].toLowerCase();
var b = new Bench('native-dns', mine, COUNT, con); var concurrent = parseInt(argv[1]);

var queries = parseInt(argv[2]);
a.on('end', function() {
var check = function() { if (['stock', 'native-dns'].indexOf(library_name) === -1) {
if (!mine.platform.ready) { opt.showHelp();
nextTick(function() { console.error('library should be one of: stock, native-dns\r\n');
check(); process.exit(1);
}); }
} else {
con = CON.pop(); if (isNaN(concurrent) || isNaN(queries)) {
b.on('end', nextIter); opt.showHelp();
b.start(); console.error('concurrency and queries should be integers');
} process.exit(1);
} }
check();
}); var library;


a.start(); if (library_name === 'stock') {
}; library = require('dns');

} else {
nextIter(); library = require('./dns');

// to be fair don't cache
var end = function() { library.platform.cache = false;
}

var bench = new Bench(library_name, library, queries, concurrent);

function check() {
if (library.platform && !library.platform.ready)
nextTick(check)
else
bench.start()
}

bench.on('end', function () {
Object.keys(results).forEach(function(library) { Object.keys(results).forEach(function(library) {
var l = results[library]; var l = results[library];
Object.keys(results[library]).forEach(function(concurrency) { Object.keys(results[library]).forEach(function(concurrency) {
var r = l[concurrency]; var r = l[concurrency];
console.log(library, concurrency, r.time, r.qps); console.log(library, concurrency, r.time, r.qps);
}); });
}); });
}; });

check();
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -24,6 +24,7 @@
"test": "nodeunit test" "test": "nodeunit test"
}, },
"devDependencies": { "devDependencies": {
"optimist": "",
"nodeunit": ">= 0.7.4" "nodeunit": ">= 0.7.4"
} }
} }

0 comments on commit 12bad04

Please sign in to comment.