-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrunBenchmark.js
More file actions
35 lines (25 loc) · 889 Bytes
/
Copy pathrunBenchmark.js
File metadata and controls
35 lines (25 loc) · 889 Bytes
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
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] || 10);
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) => { stopOnError |= !!err }
);
}
if (i < numTransactions && !stopOnError) {
setTimeout(batch, 100);
}
process.stdout.write('.');
}
setTimeout(batch, 100);