Merge branch 'benchmark'
This commit is contained in:
commit
f16eaa8555
17
benchmark/835f71a76f.txt
Normal file
17
benchmark/835f71a76f.txt
Normal file
@ -0,0 +1,17 @@
|
||||
benchmark
|
||||
starting simple-query-parsing
|
||||
3703 ops/sec - (100/0.027)
|
||||
7299 ops/sec - (1000/0.137)
|
||||
8888 ops/sec - (10000/1.125)
|
||||
8733 ops/sec - (10000/1.145)
|
||||
8810 ops/sec - (10000/1.135)
|
||||
8771 ops/sec - (10000/1.14)
|
||||
starting prepared-statement-parsing
|
||||
3846 ops/sec - (100/0.026)
|
||||
7299 ops/sec - (1000/0.137)
|
||||
7225 ops/sec - (10000/1.384)
|
||||
7288 ops/sec - (10000/1.372)
|
||||
7225 ops/sec - (10000/1.384)
|
||||
7457 ops/sec - (10000/1.341)
|
||||
done
|
||||
|
17
benchmark/df766c913.txt
Normal file
17
benchmark/df766c913.txt
Normal file
@ -0,0 +1,17 @@
|
||||
benchmark
|
||||
starting simple-query-parsing
|
||||
3571 ops/sec - (100/0.028)
|
||||
7299 ops/sec - (1000/0.137)
|
||||
8873 ops/sec - (10000/1.127)
|
||||
8536 ops/sec - (40000/4.686)
|
||||
8494 ops/sec - (40000/4.709)
|
||||
7695 ops/sec - (40000/5.198)
|
||||
starting prepared-statement-parsing
|
||||
4000 ops/sec - (100/0.025)
|
||||
6944 ops/sec - (1000/0.144)
|
||||
7153 ops/sec - (10000/1.398)
|
||||
7127 ops/sec - (40000/5.612)
|
||||
7208 ops/sec - (40000/5.549)
|
||||
6460 ops/sec - (40000/6.191)
|
||||
done
|
||||
|
42
benchmark/index.js
Normal file
42
benchmark/index.js
Normal file
@ -0,0 +1,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')
|
||||
})
|
73
benchmark/prepared-statement-parsing.js
Normal file
73
benchmark/prepared-statement-parsing.js
Normal file
@ -0,0 +1,73 @@
|
||||
var Client = require(__dirname + '/../lib/client');
|
||||
var buffers = require(__dirname + '/../test/test-buffers');
|
||||
require(__dirname + '/../test/unit/test-helper');
|
||||
|
||||
var stream = new MemoryStream();
|
||||
stream.readyState = 'open';
|
||||
var client = new Client({
|
||||
stream: stream
|
||||
});
|
||||
|
||||
var rowDescription = new buffers.rowDescription([{
|
||||
name: 'id',
|
||||
tableID: 1,
|
||||
attributeNumber: 1,
|
||||
dataTypeID: 23, //int4
|
||||
typeModifer: 0,
|
||||
formatCode: 0
|
||||
},{
|
||||
name: 'name',
|
||||
tableID: 1,
|
||||
attributeNumber: 2,
|
||||
dataTypeID: 25, //text
|
||||
typeModifer: 0,
|
||||
formatCode: 0 //text format
|
||||
}, {
|
||||
name: 'comment',
|
||||
tableID: 1,
|
||||
attributeNumber: 3,
|
||||
dataTypeID: 25, //text
|
||||
typeModifer: 0,
|
||||
formatCode: 0 //text format
|
||||
}]);
|
||||
var row1 = buffers.dataRow(['1', 'Brian', 'Something groovy']);
|
||||
var row2 = buffers.dataRow(['2', 'Bob', 'Testint test']);
|
||||
var row3 = buffers.dataRow(['3', 'The amazing power of the everlasting gobstopper', 'okay now']);
|
||||
var parseCompleteBuffer = buffers.parseComplete();
|
||||
var bindCompleteBuffer = buffers.bindComplete();
|
||||
var portalSuspendedBuffer = buffers.portalSuspended();
|
||||
var complete = buffers.commandComplete('SELECT 3');
|
||||
var ready = buffers.readyForQuery();
|
||||
var buffer = Buffer.concat([parseCompleteBuffer,
|
||||
bindCompleteBuffer,
|
||||
rowDescription,
|
||||
row1,
|
||||
row2,
|
||||
row3,
|
||||
portalSuspendedBuffer,
|
||||
row1,
|
||||
row2,
|
||||
row3,
|
||||
portalSuspendedBuffer,
|
||||
row1,
|
||||
row2,
|
||||
row3,
|
||||
portalSuspendedBuffer,
|
||||
complete, ready]);
|
||||
|
||||
var bufferSlice = require('buffer-slice');
|
||||
var buffers = bufferSlice(10, buffer);
|
||||
|
||||
client.connect(assert.calls(function() {
|
||||
client.connection.emit('readyForQuery');
|
||||
module.exports = function() {
|
||||
return function(done) {
|
||||
client.query('SELECT * FROM whatever WHERE this = "doesnt even matter"', ['whatever'], function(err, res) {
|
||||
assert.equal(res.rows.length, 9);
|
||||
done();
|
||||
});
|
||||
buffers.forEach(stream.emit.bind(stream, 'data'));
|
||||
};
|
||||
};
|
||||
}));
|
||||
client.connection.emit('readyForQuery');
|
59
benchmark/simple-query-parsing.js
Normal file
59
benchmark/simple-query-parsing.js
Normal file
@ -0,0 +1,59 @@
|
||||
var Client = require(__dirname + '/../lib/client');
|
||||
var buffers = require(__dirname + '/../test/test-buffers');
|
||||
require(__dirname + '/../test/unit/test-helper');
|
||||
|
||||
var stream = new MemoryStream();
|
||||
stream.readyState = 'open';
|
||||
var client = new Client({
|
||||
stream: stream
|
||||
});
|
||||
|
||||
var rowDescription = new buffers.rowDescription([{
|
||||
name: 'id',
|
||||
tableID: 1,
|
||||
attributeNumber: 1,
|
||||
dataTypeID: 23, //int4
|
||||
typeModifer: 0,
|
||||
formatCode: 0
|
||||
},{
|
||||
name: 'name',
|
||||
tableID: 1,
|
||||
attributeNumber: 2,
|
||||
dataTypeID: 25, //text
|
||||
typeModifer: 0,
|
||||
formatCode: 0 //text format
|
||||
}, {
|
||||
name: 'comment',
|
||||
tableID: 1,
|
||||
attributeNumber: 3,
|
||||
dataTypeID: 25, //text
|
||||
typeModifer: 0,
|
||||
formatCode: 0 //text format
|
||||
}]);
|
||||
var row1 = buffers.dataRow(['1', 'Brian', 'Something groovy']);
|
||||
var row2 = buffers.dataRow(['2', 'Bob', 'Testint test']);
|
||||
var row3 = buffers.dataRow(['3', 'The amazing power of the everlasting gobstopper', 'okay now']);
|
||||
var complete = buffers.commandComplete('SELECT 3');
|
||||
var ready = buffers.readyForQuery();
|
||||
var buffer = Buffer.concat([
|
||||
rowDescription,
|
||||
row1, row2, row3,
|
||||
row1, row2, row3,
|
||||
row1, row2, row3,
|
||||
complete, ready]);
|
||||
var bufferSlice = require('buffer-slice');
|
||||
buffers = bufferSlice(10, buffer);
|
||||
|
||||
client.connect(assert.calls(function() {
|
||||
client.connection.emit('readyForQuery');
|
||||
module.exports = function() {
|
||||
return function(done) {
|
||||
client.query('SELECT * FROM whatever WHERE this = "doesnt even matter"', function(err, res) {
|
||||
assert.equal(res.rows.length, 9);
|
||||
done();
|
||||
});
|
||||
buffers.forEach(stream.emit.bind(stream, 'data'));
|
||||
};
|
||||
};
|
||||
}));
|
||||
client.connection.emit('readyForQuery');
|
@ -474,7 +474,7 @@ Connection.prototype.parseT = function(msg) {
|
||||
msg.fieldCount = this.parseInt16();
|
||||
var fields = [];
|
||||
for(var i = 0; i < msg.fieldCount; i++){
|
||||
fields[i] = this.parseField();
|
||||
fields.push(this.parseField());
|
||||
}
|
||||
msg.fields = fields;
|
||||
return msg;
|
||||
@ -498,7 +498,11 @@ Connection.prototype.parseD = function(msg) {
|
||||
var fields = [];
|
||||
for(var i = 0; i < fieldCount; i++) {
|
||||
var length = this.parseInt32();
|
||||
fields[i] = (length === -1 ? null : this.readBytes(length));
|
||||
var value = null;
|
||||
if(length !== -1) {
|
||||
value = this.readBytes(length);
|
||||
}
|
||||
fields.push(value);
|
||||
}
|
||||
msg.fieldCount = fieldCount;
|
||||
msg.fields = fields;
|
||||
@ -553,49 +557,35 @@ Connection.prototype.parseA = function(msg) {
|
||||
};
|
||||
|
||||
Connection.prototype.parseGH = function (msg) {
|
||||
msg.binary = Boolean(this.parseInt8());
|
||||
var isBinary = this.buffer[this.offset] !== 0;
|
||||
this.offset++;
|
||||
msg.binary = isBinary;
|
||||
var columnCount = this.parseInt16();
|
||||
msg.columnTypes = [];
|
||||
for(var i = 0; i<columnCount; i++) {
|
||||
msg.columnTypes[i] = this.parseInt16();
|
||||
msg.columnTypes.push(this.parseInt16());
|
||||
}
|
||||
return msg;
|
||||
};
|
||||
|
||||
Connection.prototype.parseInt8 = function () {
|
||||
var value = Number(this.buffer[this.offset]);
|
||||
this.offset++;
|
||||
return value;
|
||||
};
|
||||
|
||||
Connection.prototype.readChar = function() {
|
||||
return Buffer([this.buffer[this.offset++]]).toString(this.encoding);
|
||||
};
|
||||
|
||||
Connection.prototype.parseInt32 = function() {
|
||||
var value = this.peekInt32();
|
||||
var value = this.buffer.readInt32BE(this.offset, true);
|
||||
this.offset += 4;
|
||||
return value;
|
||||
};
|
||||
|
||||
Connection.prototype.peekInt32 = function(offset) {
|
||||
offset = offset || this.offset;
|
||||
var buffer = this.buffer;
|
||||
return ((buffer[offset++] << 24) +
|
||||
(buffer[offset++] << 16) +
|
||||
(buffer[offset++] << 8) +
|
||||
buffer[offset++]);
|
||||
};
|
||||
|
||||
|
||||
Connection.prototype.parseInt16 = function() {
|
||||
return ((this.buffer[this.offset++] << 8) +
|
||||
(this.buffer[this.offset++] << 0));
|
||||
var value = this.buffer.readInt16BE(this.offset, true);
|
||||
this.offset += 2;
|
||||
return value;
|
||||
};
|
||||
|
||||
Connection.prototype.readString = function(length) {
|
||||
return this.buffer.toString(this.encoding, this.offset,
|
||||
(this.offset += length));
|
||||
return this.buffer.toString(this.encoding, this.offset, (this.offset += length));
|
||||
};
|
||||
|
||||
Connection.prototype.readBytes = function(length) {
|
||||
|
Loading…
Reference in New Issue
Block a user