Braydon Fuller
10 years ago
5 changed files with 94 additions and 8 deletions
File diff suppressed because one or more lines are too long
@ -0,0 +1,8 @@ |
|||
{ |
|||
"devDependencies": { |
|||
"bcoin": "0.15.0", |
|||
"bitcoinjs-lib": "^1.5.7", |
|||
"fullnode": "^0.9.0", |
|||
"benchmark": "^1.0.0" |
|||
} |
|||
} |
@ -0,0 +1,63 @@ |
|||
'use strict'; |
|||
|
|||
var benchmark = require('benchmark'); |
|||
var bitcore = require('..'); |
|||
var bitcoinjs = require('bitcoinjs-lib'); |
|||
var bcoin = require('bcoin'); |
|||
var async = require('async'); |
|||
var fullnode = require('fullnode'); |
|||
var blockData = require('./block-357238.json'); |
|||
|
|||
var maxTime = 20; |
|||
|
|||
console.log('Benchmarking Block/Transaction Serialization'); |
|||
console.log('---------------------------------------'); |
|||
|
|||
async.series([ |
|||
function(next) { |
|||
|
|||
var block1; |
|||
var block2; |
|||
var block3; |
|||
|
|||
function bitcoreTest() { |
|||
block1 = bitcore.Block.fromString(blockData); |
|||
} |
|||
|
|||
function bitcoinJSTest() { |
|||
block2 = bitcoinjs.Block.fromHex(blockData); |
|||
} |
|||
|
|||
var parser = new bcoin.protocol.parser(); |
|||
|
|||
function bcoinTest() { |
|||
var raw = bcoin.utils.toArray(blockData, 'hex'); |
|||
var data = parser.parseBlock(raw); |
|||
block3 = new bcoin.block(data, 'block'); |
|||
} |
|||
|
|||
var blockDataMessage = '0000000000000000' + blockData; // add mock leading magic and size
|
|||
|
|||
function fullnodeTest() { |
|||
fullnode.Block().fromHex(blockDataMessage); |
|||
} |
|||
|
|||
var suite = new benchmark.Suite(); |
|||
suite.add('bitcore', bitcoreTest, {maxTime: maxTime}); |
|||
suite.add('bitcoinjs', bitcoinJSTest, {maxTime: maxTime}); |
|||
suite.add('bcoin', bcoinTest, {maxTime: maxTime}); |
|||
suite.add('fullnode', fullnodeTest, {maxTime: maxTime}); |
|||
suite |
|||
.on('cycle', function(event) { |
|||
console.log(String(event.target)); |
|||
}) |
|||
.on('complete', function() { |
|||
console.log('Fastest is ' + this.filter('fastest').pluck('name')); |
|||
console.log('----------------------------------------------------------------------'); |
|||
next(); |
|||
}) |
|||
.run(); |
|||
} |
|||
], function(err) { |
|||
console.log('Finished'); |
|||
}); |
Loading…
Reference in new issue