git ssb

0+

wanderer🌟 / js-dfinity-radix-tree



Tree: 0e6a2ce9141d6945013b60a2d132c0a385733f90

Files: 0e6a2ce9141d6945013b60a2d132c0a385733f90 / benchmark / multikey.js

1901 bytesRaw
1const IPFS = require('ipfs')
2const crypto = require('crypto')
3const RadixTree = require('../')
4const cbor = require('borc')
5const zlib = require('zlib')
6
7// start ipfs
8const node = new IPFS({
9 start: false,
10 repo: './ipfs-repo'
11})
12
13node.on('ready', async () => {
14 const tree = new RadixTree({
15 dag: node.dag,
16 // root: { '/': 'zdpuArkpWFfw49S1tNLY26YNkHCoKt2CG7rJ6iCaqkcwsGqH7' }
17 })
18
19 const entries = 10000 //5117051
20 console.log('entries', entries)
21 for (let i = 0; i < entries; i++) {
22 const key = crypto.createHash('sha256').update(i.toString()).digest().slice(0, 20)
23 await tree.set(key, i)
24 }
25 console.log('flushing')
26 const sr = await tree.flush()
27 console.log('done', sr)
28
29 let proofSize = 0
30 let compressedSize = 0
31
32 const gzip = zlib.createGzip()
33 gzip.on('data', (data) => {
34 compressedSize += data.length
35 })
36
37 const numOfKeys = 3
38 for (let i = 0; i < numOfKeys; i++) {
39 const key = crypto.createHash('sha256').update(i.toString()).digest().slice(0, 20)
40 await tree.get(key)
41 }
42
43 const encoded = cbor.encode(tree.root)
44 proofSize += encoded.length
45
46 const promise = new Promise((resolve, reject) => {
47 gzip.on('end', () => {
48 resolve()
49 })
50 })
51 gzip.end(encoded)
52 await promise
53 console.log('cbor size', proofSize)
54 console.log('compressed size', compressedSize)
55})
56
57// if (i % 10000 === 0) {
58// console.log(i)
59// console.log(JSON.stringify(tree.root, null, 2))
60// try {
61// let start = new Date()
62// let hrstart = process.hrtime()
63// await tree.flush()
64// const end = new Date() - start
65// const hrend = process.hrtime(hrstart)
66
67// console.info('Execution time: %dms', end)
68// console.info('Execution time (hr): %ds %dms', hrend[0], hrend[1] / 1000000)
69// console.log(tree.root)
70// start = new Date()
71// hrstart = process.hrtime()
72// } catch (e) {
73// console.log(e)
74// }
75// }
76

Built with git-ssb-web