work in benchmark
This commit is contained in:
parent
df766c9134
commit
a28f156347
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
|
||||
|
@ -1,45 +1,42 @@
|
||||
var profiler = require('profiler');
|
||||
var Client = require(__dirname + '/../lib/client');
|
||||
var buffers = require(__dirname + '/../test/test-buffers');
|
||||
require(__dirname + '/../test/unit/test-helper');
|
||||
console.log('');
|
||||
var async = require('async');
|
||||
var max = 40000;
|
||||
var maxTimes = 3;
|
||||
var doLoops = function(bench, loops, times, cb) {
|
||||
var start = new Date();
|
||||
var count = 0;
|
||||
|
||||
var stream = new MemoryStream();
|
||||
stream.readyState = 'open';
|
||||
var client = new Client({
|
||||
stream: stream
|
||||
});
|
||||
|
||||
var rowDescription = new buffers.rowDescription([{
|
||||
name: 'name',
|
||||
tableID: 1,
|
||||
attributeNumber: 1,
|
||||
dataTypeID: 25, //text
|
||||
typeModifer: 0,
|
||||
formatCode: 0 //text format
|
||||
}]);
|
||||
var row1 = buffers.dataRow(['Brian']);
|
||||
var row2 = buffers.dataRow(['Bob']);
|
||||
var row3 = buffers.dataRow(['The amazing power of the everlasting gobstopper']);
|
||||
var complete = buffers.commandComplete('SELECT 3');
|
||||
var ready = buffers.readyForQuery();
|
||||
var buffer = Buffer.concat([rowDescription, row1, row2, row3, complete, ready]);
|
||||
|
||||
client.connect(assert.calls(function() {
|
||||
client.connection.emit('readyForQuery');
|
||||
|
||||
var callCount = 0;
|
||||
var max = 1000;
|
||||
profiler.resume();
|
||||
for(var i = 0; i < max; i++) {
|
||||
//BEGIN BENCH
|
||||
client.query('SELECT * FROM whatever WHERE this = "doesnt even matter"', function(err, res) {
|
||||
callCount++;
|
||||
});
|
||||
//END BENCH
|
||||
stream.emit('data', buffer);
|
||||
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);
|
||||
}
|
||||
profiler.pause();
|
||||
assert.equal(callCount, max);
|
||||
}));
|
||||
client.connection.emit('readyForQuery');
|
||||
|
||||
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');
|
Loading…
Reference in New Issue
Block a user