bench: refactor tx bench.

This commit is contained in:
Christopher Jeffrey 2017-08-09 15:26:00 -07:00
parent ff8b0418b1
commit bb008c50a1
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -1,8 +1,6 @@
/* eslint max-len: "off" */
'use strict';
const fs = require('fs');
const fs = require('../lib/utils/fs');
const Block = require('../lib/primitives/block');
const Address = require('../lib/primitives/address');
const TX = require('../lib/primitives/tx');
@ -13,10 +11,12 @@ const random = require('../lib/crypto/random');
const common = require('../test/util/common');
const bench = require('./bench');
const block300025 = fs.readFileSync(`${__dirname}/../test/data/block300025.raw`);
const undo300025 = fs.readFileSync(`${__dirname}/../test/data/undo300025.raw`);
const block = Block.fromRaw(block300025);
const undo = common.parseUndo(undo300025);
const blockRaw = fs.readFileSync(`${__dirname}/../test/data/block300025.raw`);
const undoRaw = fs.readFileSync(`${__dirname}/../test/data/undo300025.raw`);
const block = Block.fromRaw(blockRaw);
const undo = common.parseUndo(undoRaw);
const btx = {
tx: block.txs[397],
view: common.applyUndo(block, undo)
@ -28,93 +28,117 @@ const raw = tx5.tx.toRaw();
{
const end = bench('parse');
for (let i = 0; i < 1000; i++)
TX.fromRaw(raw);
end(1000);
}
{
const end = bench('serialize');
for (let i = 0; i < 1000; i++) {
tx5.tx._raw = null;
tx5.tx.toRaw();
}
end(1000);
}
{
const end = bench('hash');
for (let i = 0; i < 3000; i++) {
tx3.tx.hash();
tx3.tx._hash = null;
}
end(3000);
}
{
const end = bench('witness hash');
for (let i = 0; i < 3000; i++) {
tx5.tx.witnessHash();
tx5.tx._whash = null;
}
end(3000);
}
{
const end = bench('sanity');
for (let i = 0; i < 1000; i++)
tx5.tx.isSane();
end(1000);
}
{
const end = bench('input hashes');
for (let i = 0; i < 1000; i++)
tx5.tx.getInputHashes(null, 'hex');
end(1000);
}
{
const end = bench('output hashes');
for (let i = 0; i < 1000; i++)
tx5.tx.getOutputHashes('hex');
end(1000);
}
{
const end = bench('all hashes');
for (let i = 0; i < 1000; i++)
tx5.tx.getHashes(null, 'hex');
end(1000);
}
{
const end = bench('verify');
for (let i = 0; i < 3000; i++)
tx3.tx.verify(tx3.view, Script.flags.VERIFY_P2SH);
end(3000 * tx3.tx.inputs.length);
}
{
const end = bench('verify2');
const script = tx3.view.getOutputFor(tx3.tx.inputs[0]).script;
const {script} = tx3.view.getOutputFor(tx3.tx.inputs[0]);
for (let i = 0; i < 100000; i++)
tx3.tx.signatureHashV0(0, script, Script.hashType.ALL);
end(100000);
}
{
const end = bench('fee');
for (let i = 0; i < 1000; i++)
tx3.tx.getFee(tx3.view);
end(1000);
}
{
const flags = Script.flags.VERIFY_P2SH | Script.flags.VERIFY_DERSIG;
const end = bench('verify multisig');
for (let i = 0; i < 3000; i++)
btx.tx.verify(btx.view, flags);
end(3000 * btx.tx.inputs.length);
}
@ -141,21 +165,27 @@ const tx2 = mtx.toTX();
{
const end = bench('input hashes');
for (let i = 0; i < 1000; i++)
tx2.getInputHashes(null, 'hex');
end(1000);
}
{
const end = bench('output hashes');
for (let i = 0; i < 1000; i++)
tx2.getOutputHashes('hex');
end(1000);
}
{
const end = bench('all hashes');
for (let i = 0; i < 1000; i++)
tx2.getHashes(null, 'hex');
end(1000);
}