forked from ethereumjs/merkle-patricia-tree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom.js
44 lines (39 loc) · 897 Bytes
/
random.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
// https://github.com/ethereum/wiki/wiki/Benchmarks
'use strict'
const Trie = require('../')
const ethUtil = require('ethereumjs-util')
const async = require('async')
const ROUNDS = 1000
const SYMMETRIC = true
const ERA_SIZE = 1000
let trie = new Trie()
let seed = new Buffer(32).fill(0)
let testName = 'rounds ' + ROUNDS + ' ' + ERA_SIZE + ' ' + SYMMETRIC ? 'sys' : 'rand'
console.time(testName)
run(() => {
console.timeEnd(testName)
})
function run (cb) {
let i = 0
async.whilst(
() => {
i++
return i <= ROUNDS
},
function (done) {
seed = ethUtil.sha3(seed)
if (SYMMETRIC) {
trie.put(seed, seed, genRoot)
} else {
let val = ethUtil.sha3(seed)
trie.put(seed, val, genRoot)
}
function genRoot () {
if (i % ERA_SIZE === 0) {
seed = trie.root
}
done()
}
}, cb
)
}