clean up connection slightly & add initial bench

This commit is contained in:
bmc 2013-04-08 16:44:41 -05:00
parent 835f71a76f
commit ca5c10a02f
2 changed files with 32 additions and 25 deletions

17
benchmark/835f71a76f.txt Normal file
View 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

View File

@ -474,7 +474,7 @@ Connection.prototype.parseT = function(msg) {
msg.fieldCount = this.parseInt16(); msg.fieldCount = this.parseInt16();
var fields = []; var fields = [];
for(var i = 0; i < msg.fieldCount; i++){ for(var i = 0; i < msg.fieldCount; i++){
fields[i] = this.parseField(); fields.push(this.parseField());
} }
msg.fields = fields; msg.fields = fields;
return msg; return msg;
@ -498,7 +498,11 @@ Connection.prototype.parseD = function(msg) {
var fields = []; var fields = [];
for(var i = 0; i < fieldCount; i++) { for(var i = 0; i < fieldCount; i++) {
var length = this.parseInt32(); 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.fieldCount = fieldCount;
msg.fields = fields; msg.fields = fields;
@ -553,49 +557,35 @@ Connection.prototype.parseA = function(msg) {
}; };
Connection.prototype.parseGH = 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(); var columnCount = this.parseInt16();
msg.columnTypes = []; msg.columnTypes = [];
for(var i = 0; i<columnCount; i++) { for(var i = 0; i<columnCount; i++) {
msg.columnTypes[i] = this.parseInt16(); msg.columnTypes.push(this.parseInt16());
} }
return msg; return msg;
}; };
Connection.prototype.parseInt8 = function () {
var value = Number(this.buffer[this.offset]);
this.offset++;
return value;
};
Connection.prototype.readChar = function() { Connection.prototype.readChar = function() {
return Buffer([this.buffer[this.offset++]]).toString(this.encoding); return Buffer([this.buffer[this.offset++]]).toString(this.encoding);
}; };
Connection.prototype.parseInt32 = function() { Connection.prototype.parseInt32 = function() {
var value = this.peekInt32(); var value = this.buffer.readInt32BE(this.offset, true);
this.offset += 4; this.offset += 4;
return value; 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() { Connection.prototype.parseInt16 = function() {
return ((this.buffer[this.offset++] << 8) + var value = this.buffer.readInt16BE(this.offset, true);
(this.buffer[this.offset++] << 0)); this.offset += 2;
return value;
}; };
Connection.prototype.readString = function(length) { Connection.prototype.readString = function(length) {
return this.buffer.toString(this.encoding, this.offset, return this.buffer.toString(this.encoding, this.offset, (this.offset += length));
(this.offset += length));
}; };
Connection.prototype.readBytes = function(length) { Connection.prototype.readBytes = function(length) {