Patrick Nagurny
10 years ago
3 changed files with 118 additions and 8 deletions
@ -0,0 +1,70 @@ |
|||
'use strict'; |
|||
|
|||
var benchmark = require('benchmark'); |
|||
var bitcore = require('..'); |
|||
var async = require('async'); |
|||
var blockData = require('./block-357238.json'); |
|||
|
|||
var maxTime = 10; |
|||
|
|||
console.log('Benchmarking Script'); |
|||
console.log('---------------------------------------'); |
|||
|
|||
async.series([ |
|||
function(next) { |
|||
|
|||
var c = 0; |
|||
var scripts = []; |
|||
var block = bitcore.Block.fromString(blockData); |
|||
for (var i = 0; i < block.transactions.length; i++) { |
|||
var tx = block.transactions[i]; |
|||
for (var j = 0; j < tx.inputs.length; j++) { |
|||
var input = tx.inputs[j]; |
|||
if (input.script) { |
|||
scripts.push(input.script); |
|||
} |
|||
} |
|||
} |
|||
|
|||
function isPublicKeyHashIn() { |
|||
if (c >= scripts.length) { |
|||
c = 0; |
|||
} |
|||
scripts[c].isPublicKeyHashIn(); |
|||
c++; |
|||
} |
|||
|
|||
function toAddress() { |
|||
if (c >= scripts.length) { |
|||
c = 0; |
|||
} |
|||
scripts[c].toAddress(); |
|||
c++; |
|||
} |
|||
|
|||
function getAddressInfo() { |
|||
if (c >= scripts.length) { |
|||
c = 0; |
|||
} |
|||
scripts[c].getAddressInfo(); |
|||
c++; |
|||
} |
|||
|
|||
var suite = new benchmark.Suite(); |
|||
suite.add('isPublicKeyHashIn', isPublicKeyHashIn, {maxTime: maxTime}); |
|||
suite.add('toAddress', toAddress, {maxTime: maxTime}); |
|||
suite.add('getAddressInfo', getAddressInfo, {maxTime: maxTime}); |
|||
suite |
|||
.on('cycle', function(event) { |
|||
console.log(String(event.target)); |
|||
}) |
|||
.on('complete', function() { |
|||
console.log('Done'); |
|||
console.log('----------------------------------------------------------------------'); |
|||
next(); |
|||
}) |
|||
.run(); |
|||
} |
|||
], function(err) { |
|||
console.log('Finished'); |
|||
}); |
Loading…
Reference in new issue