git ssb

0+

wanderer🌟 / js-dfinity-radix-tree



Tree: ad9db87c1c97950a008f8f2e0ea3d81cf300cf06

Files: ad9db87c1c97950a008f8f2e0ea3d81cf300cf06 / benchmark / ethereum.js

944 bytesRaw
1var Trie = require('merkle-patricia-tree')
2const crypto = require('crypto')
3const rlp = require('rlp')
4
5const trie = new Trie()
6
7const entries = 100000
8console.log('entries', entries)
9
10async function run () {
11 for (let i = 0; i < entries; i++) {
12 const key = crypto.createHash('sha256').update(i.toString()).digest().slice(0, 20)
13 await new Promise((resolve, reject) => {
14 trie.put(key, i, resolve)
15 })
16 }
17
18 let proofSize = 0
19 for (let i = 0; i < entries; i++) {
20 const key = crypto.createHash('sha256').update(i.toString()).digest().slice(0, 20)
21 const promise = new Promise((resolve, reject) => {
22 trie.findPath(key, (err, node, remainder, stack) => {
23 let proof = stack.map(el => {
24 return el.raw
25 })
26 let encoded = rlp.encode(proof)
27 proofSize += encoded.length
28 resolve()
29 })
30 })
31 await promise
32 }
33 console.log('rlp size', proofSize / entries)
34}
35
36run()
37

Built with git-ssb-web