forked from moneybutton/bsv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.js
50 lines (45 loc) · 1.43 KB
/
benchmark.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const bsv = require('./dist/bsv')
const Address = bsv.Address
const PrivKey = bsv.PrivKey
const PubKey = bsv.PubKey
const TxBuilder = bsv.TxBuilder
const TxOut = bsv.TxOut
const Random = bsv.Random
const Bn = bsv.Bn
const KeyPair = bsv.KeyPair
var randhex = 'adf4953b2e679fdc453d9cec93ba26c3bd9f0fb875975f3d72ed0c6c6835e26e'
var randbn = new Bn().fromHex(randhex)
var privateKey = PrivKey.fromBn(randbn)
var publicKey = PubKey.fromPrivKey(privateKey)
var keyPair = new KeyPair(privateKey, publicKey)
var fromAddress = Address.fromPrivKey(privateKey)
var toAddress = fromAddress
var changeAddress = toAddress
const n = 10000
const satoshis = 1e3
// const total = satoshis * n - satoshis / 2
let txb = new TxBuilder()
for (let i = 0; i < n; i++) {
const txOut = TxOut.fromProperties(new Bn(satoshis), fromAddress.toTxOutScript())
const txHashBuf = Random.getRandomBuffer(32)
const txOutNum = 0
txb.inputFromPubKeyHash(txHashBuf, txOutNum, txOut, publicKey)
}
txb = txb.outputToAddress(new Bn(satoshis), toAddress)
txb = txb.setChangeAddress(changeAddress)
txb.setFeePerKbNum(500)
const useAllInputs = true
{
const start = Date.now()
txb.build({ useAllInputs })
const finish = Date.now()
console.log('building: ', finish - start, 'ms')
}
{
const start = Date.now()
for (let i = 0; i < txb.txIns.length; i++) {
txb.signTxIn(i, keyPair)
}
const finish = Date.now()
console.log('', n, 'inputs', 'signing: ', finish - start, 'ms')
}