-
Notifications
You must be signed in to change notification settings - Fork 1
/
averageMineRate.js
40 lines (30 loc) · 1.12 KB
/
averageMineRate.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
import Blockchain from "./blockchain.js";
const blockchain = new Blockchain();
console.log(
`Genesis Block: ${JSON.stringify(
blockchain.chain[blockchain.chain.length - 1]
)}`
);
blockchain.addBlock({ data: "block_initial" });
console.log(
`Initial Block: ${JSON.stringify(
blockchain.chain[blockchain.chain.length - 1]
)}`
);
let prevBlock, currentBlock, timeInterval, totalTimeInterval, averageMineRate;
const timeIntervals = [];
for (let i = 1; i <= 1000; i++) {
prevBlock = blockchain.chain[blockchain.chain.length - 1];
blockchain.addBlock({ data: `block_${i}` });
currentBlock = blockchain.chain[blockchain.chain.length - 1];
timeInterval = currentBlock.timestamp - prevBlock.timestamp;
timeIntervals.push(timeInterval);
totalTimeInterval = 0;
for (const interval of timeIntervals) {
totalTimeInterval += interval;
}
averageMineRate = totalTimeInterval / timeIntervals.length;
console.log(
`Block ${i}) MineTime: ${timeInterval}ms, Difficulty: ${currentBlock.difficulty}, Nonce: ${currentBlock.nonce}, averageMineRate: ${averageMineRate}ms`
);
}