该函数应该放在 blockchain-demo.js 文件中的 mine() 函数中。

最后,在控制台中输出同一难度下的16次挖矿所消耗的时间,并计算其平均值:

var times = [];
for (var i = 1; i <= 16; i++) {
  mine(i, 1, true);
  times.push(end - start);
}
console.log('Times taken to mine 16 blocks in chain 1: ' + times);
var sum = times.reduce((a, b) => a + b, 0);
var avg = sum / times.length;
console.log('Average time taken to mine a block in chain 1: ' + avg + 'ms');
区块链演示:控制台输出挖矿时间

原文地址: https://www.cveoy.top/t/topic/f2xq 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录