forked from jorpic/eth-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunBenchmark.js
42 lines (32 loc) · 1012 Bytes
/
runBenchmark.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
const fs = require('fs')
const Web3 = require('web3')
const web3 = new Web3()
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'))
const transactionPerSecond = Number.parseInt(process.argv[2] || 10000)
const transactionsPer100Ms = Math.ceil(transactionPerSecond / 10)
console.log((transactionsPer100Ms * 10) + ' transactions per second')
const transactions = fs.readFileSync('transactions.txt', 'ascii').split('\n')
const numTransactions = transactions.length
let stopOnError = false
let i = 0
function batch() {
const maxI = Math.min(i + transactionsPer100Ms, numTransactions)
for (; i < maxI; ++i) {
web3.eth.sendRawTransaction(
transactions[i],
(err,res) => {
if (err)
{
stopOnError = err
}
}
)
}
if (i < numTransactions && !stopOnError) {
setTimeout(batch, 100)
} else if (stopOnError) {
process.stdout.write(JSON.stringify(stopOnError))
}
process.stdout.write('.')
}
setTimeout(batch, 100)