-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.js
118 lines (87 loc) · 3.39 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**
iZ³ | Izzzio blockchain - https://izzz.io
@author: Andrey Nedobylsky (admin@twister-vl.ru)
EDUCERT - blockchain certificates checker
*/
let DApp = require('../app/DApp');
let BenchmarkBlock = require('./BenchmarkBlock');
class App extends DApp {
init() {
let that = this;
const CONFIG = that.config;
const TRANSACTIONS_PER_BLOCK = !CONFIG.benchmark || !CONFIG.benchmark.transactionsPerBlock ? 2500 : CONFIG.benchmark.transactionsPerBlock;
/**
* Makes simple transaction string
* Ethereum ETH transfer trasnaction
* @return {string}
*/
function makeBinaryTransaction() {
return "915b3779593a7c124b932063789297293f13625429d5527caa78f1946a409fa6acaf14a0a4a0274b37e11d6009f8281ac42992c5133bb17d25aae5bde0599dbd96face29ba1d671502a923754";
}
/**
* Makes pack of transactions
*/
function makeTransactionsList() {
let list = [];
for (let i = 0; i < TRANSACTIONS_PER_BLOCK; i++) {
list.push(makeBinaryTransaction());
}
return list;
}
const TRANSACTION_LIST = makeTransactionsList();
let newBLock = new BenchmarkBlock(TRANSACTION_LIST);
/**
* Creates new block
* @param cb
*/
function addNewBlock(cb) {
that.generateAndAddBlock(newBLock, function blockGenerated(generatedBlock) {
cb();
});
}
console.log('iZ³ Speed Benchmark loaded');
console.log();
console.log('Benchmark configuration: ');
console.log('TX per block: ' + TRANSACTIONS_PER_BLOCK);
console.log();
console.log('Starting in 10 seconds...');
console.log();
let blockCounter = 0;
let lastTime = new Date();
let lastBlocks = 0;
let recordBlocks = 0;
setTimeout(function () {
function addBlock() {
addNewBlock(function () {
blockCounter++;
setTimeout(function () {
addBlock();
}, 1);
});
}
addBlock();
setInterval(function () {
let time = (new Date()).getTime() - lastTime.getTime();
let blocks = blockCounter - lastBlocks;
let blocksSec = (blocks / time) * 1000;
console.log('\x1Bc');
console.log('iZ³ Speed Benchmark');
console.log();
console.log('Benchmark: Perfomance: Generated blocks: ' + blockCounter + ' Transactions: ' + (blockCounter * TRANSACTIONS_PER_BLOCK));
console.log('Benchmark: Perfomance: Blocks per second: ' + (blocksSec) + ' TX per second: ' + (blocksSec * TRANSACTIONS_PER_BLOCK));
console.log('Benchmark: Perfomance: Blocks max: ' + (recordBlocks) + ' TX max: ' + (recordBlocks * TRANSACTIONS_PER_BLOCK));
console.log();
if(blocksSec > recordBlocks) {
recordBlocks = blocksSec;
}
lastTime = new Date();
lastBlocks = blockCounter;
}, 1000);
}, 10000);
process.on('SIGINT', () => {
console.log('Terminating benchmark...');
process.exit();
});
}
}
module.exports = App;