bench: walletdb benchmark.
This commit is contained in:
parent
47c6da514d
commit
9dfe86e612
@ -8,27 +8,31 @@ var assert = require('assert');
|
||||
var scriptTypes = constants.scriptTypes;
|
||||
var bench = require('./bench');
|
||||
var co = require('../lib/utils/co');
|
||||
var crypto = require('../lib/crypto/crypto');
|
||||
|
||||
bcoin.cache();
|
||||
|
||||
var dummyInput = {
|
||||
prevout: {
|
||||
hash: constants.NULL_HASH,
|
||||
index: 0
|
||||
},
|
||||
coin: {
|
||||
version: 1,
|
||||
height: 0,
|
||||
value: 50460 * 4,
|
||||
script: new bcoin.script([]),
|
||||
coinbase: false,
|
||||
hash: constants.NULL_HASH,
|
||||
index: 0
|
||||
},
|
||||
script: new bcoin.script([]),
|
||||
witness: new bcoin.witness([]),
|
||||
sequence: 0xffffffff
|
||||
};
|
||||
function dummy() {
|
||||
var hash = crypto.randomBytes(32).toString('hex');
|
||||
return {
|
||||
prevout: {
|
||||
hash: hash,
|
||||
index: 0
|
||||
},
|
||||
coin: {
|
||||
version: 1,
|
||||
height: 0,
|
||||
value: 50460 * 4,
|
||||
script: new bcoin.script(),
|
||||
coinbase: false,
|
||||
hash: hash,
|
||||
index: 0
|
||||
},
|
||||
script: new bcoin.script(),
|
||||
witness: new bcoin.witness(),
|
||||
sequence: 0xffffffff
|
||||
};
|
||||
}
|
||||
|
||||
var walletdb = new bcoin.walletdb({
|
||||
name: 'wallet-test',
|
||||
@ -41,7 +45,7 @@ var walletdb = new bcoin.walletdb({
|
||||
|
||||
var runBench = co(function* runBench() {
|
||||
var i, j, wallet, addrs, jobs, end;
|
||||
var result, nonce, tx, options;
|
||||
var result, tx, options;
|
||||
|
||||
// Open and Create
|
||||
yield walletdb.open();
|
||||
@ -74,25 +78,42 @@ var runBench = co(function* runBench() {
|
||||
for (i = 0; i < result.length; i++)
|
||||
addrs.push(result[i].getAddress());
|
||||
|
||||
// TX
|
||||
// TX deposit
|
||||
jobs = [];
|
||||
nonce = new BN(0);
|
||||
for (i = 0; i < 10000; i++) {
|
||||
tx = bcoin.mtx()
|
||||
.addInput(dummy())
|
||||
.addOutput(addrs[(i + 0) % addrs.length], 50460)
|
||||
.addOutput(addrs[(i + 1) % addrs.length], 50460)
|
||||
.addOutput(addrs[(i + 2) % addrs.length], 50460)
|
||||
.addOutput(addrs[(i + 3) % addrs.length], 50460);
|
||||
.addOutput(addrs[(i + 3) % addrs.length], 50460)
|
||||
.toTX();
|
||||
|
||||
tx.addInput(dummyInput);
|
||||
nonce.addn(1);
|
||||
tx.inputs[0].script.set(0, nonce);
|
||||
tx.inputs[0].script.compile();
|
||||
|
||||
jobs.push(walletdb.addTX(tx.toTX()));
|
||||
jobs.push(walletdb.addTX(tx));
|
||||
}
|
||||
|
||||
end = bench('tx');
|
||||
end = bench('deposit');
|
||||
result = yield Promise.all(jobs);
|
||||
end(10000);
|
||||
|
||||
// TX redemption
|
||||
jobs = [];
|
||||
for (i = 0; i < 10000; i++) {
|
||||
tx = bcoin.mtx()
|
||||
.addInput(tx, 0)
|
||||
.addInput(tx, 1)
|
||||
.addInput(tx, 2)
|
||||
.addInput(tx, 3)
|
||||
.addOutput(addrs[(i + 0) % addrs.length], 50460)
|
||||
.addOutput(addrs[(i + 1) % addrs.length], 50460)
|
||||
.addOutput(addrs[(i + 2) % addrs.length], 50460)
|
||||
.addOutput(addrs[(i + 3) % addrs.length], 50460)
|
||||
.toTX();
|
||||
|
||||
jobs.push(walletdb.addTX(tx));
|
||||
}
|
||||
|
||||
end = bench('redemption');
|
||||
result = yield Promise.all(jobs);
|
||||
end(10000);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user