mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-25 16:03:13 +00:00
update bench to include more libpq/javascript compare
This commit is contained in:
parent
c75c6e3040
commit
3dc12b71bd
@ -7,7 +7,7 @@ var round = function(num) {
|
||||
return Math.round((num*1000))/1000
|
||||
}
|
||||
|
||||
var doBenchmark = function() {
|
||||
var doBenchmark = function(cb) {
|
||||
var bench = bencher({
|
||||
name: 'select large sets',
|
||||
repeat: 10,
|
||||
@ -15,6 +15,10 @@ var doBenchmark = function() {
|
||||
name: 'selecting string',
|
||||
run: function(next) {
|
||||
var query = client.query('SELECT name FROM items');
|
||||
query.on('error', function(er) {
|
||||
console.log(er);throw er;
|
||||
});
|
||||
|
||||
query.on('end', function() {
|
||||
next();
|
||||
});
|
||||
@ -23,6 +27,10 @@ var doBenchmark = function() {
|
||||
name: 'selecting integer',
|
||||
run: function(next) {
|
||||
var query = client.query('SELECT count FROM items');
|
||||
query.on('error', function(er) {
|
||||
console.log(er);throw er;
|
||||
});
|
||||
|
||||
query.on('end', function() {
|
||||
next();
|
||||
})
|
||||
@ -31,6 +39,10 @@ var doBenchmark = function() {
|
||||
name: 'selecting date',
|
||||
run: function(next) {
|
||||
var query = client.query('SELECT created FROM items');
|
||||
query.on('error', function(er) {
|
||||
console.log(er);throw er;
|
||||
});
|
||||
|
||||
query.on('end', function() {
|
||||
next();
|
||||
})
|
||||
@ -44,7 +56,7 @@ var doBenchmark = function() {
|
||||
})
|
||||
}
|
||||
}, {
|
||||
name: 'loading all rows into memory',
|
||||
name: 'loading all rows into memory',
|
||||
run: function(next) {
|
||||
var query = client.query('SELECT * FROM items', next);
|
||||
}
|
||||
@ -57,6 +69,7 @@ var doBenchmark = function() {
|
||||
console.log(" %s: \n average: %d ms\n total: %d ms", action.name, round(action.meanTime), round(action.totalTime));
|
||||
})
|
||||
client.end();
|
||||
cb();
|
||||
})
|
||||
}
|
||||
|
||||
@ -78,6 +91,35 @@ for(var i = 0; i < count; i++) {
|
||||
}
|
||||
|
||||
client.once('drain', function() {
|
||||
console.log('done with insert. executing benchmark.');
|
||||
doBenchmark();
|
||||
console.log('done with insert. executing pure-javascript benchmark.');
|
||||
doBenchmark(function() {
|
||||
var oldclient = client;
|
||||
client = new pg.native.Client(conString);
|
||||
client.on('error', function(err) {
|
||||
console.log(err);
|
||||
throw err;
|
||||
});
|
||||
|
||||
client.connect();
|
||||
client.connect();
|
||||
console.log();
|
||||
console.log("creating temp table");
|
||||
client.query("CREATE TEMP TABLE items(name VARCHAR(10), created TIMESTAMPTZ, count INTEGER)");
|
||||
var count = 10000;
|
||||
console.log("inserting %d rows", count);
|
||||
for(var i = 0; i < count; i++) {
|
||||
var query = {
|
||||
name: 'insert',
|
||||
text: "INSERT INTO items(name, created, count) VALUES($1, $2, $3)",
|
||||
values: ["item"+i, new Date(2010, 01, 01, i, 0, 0), i]
|
||||
};
|
||||
client.query(query);
|
||||
}
|
||||
client.once('drain', function() {
|
||||
console.log("executing native benchmark");
|
||||
doBenchmark(function() {
|
||||
console.log("all done");
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user