node-postgres/benchmark/index.js

43 lines
1.0 KiB
JavaScript
Raw Normal View History

2013-04-05 00:40:37 +08:00
var async = require('async');
2013-04-05 02:50:17 +08:00
var max = 10000;
2013-04-05 00:40:37 +08:00
var maxTimes = 3;
var doLoops = function(bench, loops, times, cb) {
var start = new Date();
var count = 0;
2013-03-19 23:07:13 +08:00
2013-04-05 00:40:37 +08:00
var done = function() {
var duration = (new Date() - start)
var seconds = (duration / 1000);
console.log("%d ops/sec - (%d/%d)", ~~(loops/seconds), loops, seconds);
var next = loops * 10;
if(next > max) {
if(times > maxTimes) return cb();
times++;
next = max;
}
setTimeout(function() {
doLoops(bench, next, times, cb);
}, 100);
}
2013-03-19 23:07:13 +08:00
2013-04-05 00:40:37 +08:00
var run = function() {
if(count++ >= loops){
return done();
}
bench(function() {
setImmediate(run);
2013-03-19 23:07:13 +08:00
});
}
2013-04-05 00:40:37 +08:00
run();
}
var bench = require(__dirname + '/simple-query-parsing');
console.log();
var benches = ['simple-query-parsing', 'prepared-statement-parsing'];
async.forEachSeries(benches, function(name, cb) {
var bench = require(__dirname + '/' + name)();
console.log('starting ', name);
doLoops(bench, 100, 1, cb);
}, function(err, res) {
console.log('done')
})