forked from brianc/node-postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (40 loc) · 1.03 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var async = require('async');
var max = 10000;
var maxTimes = 3;
var doLoops = function(bench, loops, times, cb) {
var start = new Date();
var count = 0;
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);
}
var run = function() {
if(count++ >= loops){
return done();
}
bench(function() {
setImmediate(run);
});
}
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')
})