git ssb

0+

wanderer🌟 / js-dfinity-radix-tree



Tree: 4d4aa45d37fc25f0759d091f2ed9005d37479164

Files: 4d4aa45d37fc25f0759d091f2ed9005d37479164 / benchmark / ethereum.js

1775 bytesRaw
1var Trie = require('merkle-patricia-tree')
2const crypto = require('crypto')
3// const rlp = require('rlp')
4const level = require('level')
5const db = level('./eth-testdb')
6
7db._get = db.get
8let lookups = 0
9db.get = function (key, opts, cb) {
10 lookups++
11 return db._get(key, opts, cb)
12}
13
14let trie = new Trie(db)
15
16const entries = 100000
17console.log('entries', entries)
18
19async function run () {
20
21 let start = new Date()
22 let hrstart = process.hrtime()
23
24 for (let i = 0; i < entries; i++) {
25 const key = crypto.createHash('sha256').update(i.toString()).digest().slice(0, 20)
26 await new Promise((resolve, reject) => {
27 trie.put(key, i, resolve)
28 })
29 }
30
31 let end = new Date() - start
32 let hrend = process.hrtime(hrstart)
33
34 console.info('state root creation time: %dms', end)
35 console.info('state root creation time (hr): %ds %dms', hrend[0], hrend[1] / 1000000)
36
37 start = new Date()
38 hrstart = process.hrtime()
39
40 console.log('root', trie.root.toString('hex'))
41
42 let proofSize = 0
43 for (let i = 0; i < entries; i++) {
44 const key = crypto.createHash('sha256').update(i.toString()).digest().slice(0, 20)
45 trie = new Trie(db, trie.root)
46 const promise = new Promise((resolve, reject) => {
47 trie.get(key, (err, value) => {
48 // console.log(value)
49 // let proof = stack.map(el => {
50 // return el.raw
51 // })
52 // let encoded = rlp.encode(proof)
53 // proofSize += encoded.length
54 resolve()
55 })
56 })
57 await promise
58 }
59
60 end = new Date() - start
61 hrend = process.hrtime(hrstart)
62
63 console.info('read time: %dms', end)
64 console.info('read time (hr): %ds %dms', hrend[0], hrend[1] / 1000000)
65 console.info('db lookups', lookups)
66 // console.log('rlp size', proofSize / entries)
67}
68
69run()
70

Built with git-ssb-web