git ssb

0+

wanderer🌟 / js-dfinity-radix-tree



Commit 260a23c33176d1047e9b98657c8c555a9637cb7e

added lmza benchmark

Signed-off-by: wanderer <mjbecze@gmail.com>
wanderer committed on 8/7/2017, 8:36:14 PM
Parent: d5a358aa501433d3ccc2b377b82d28c37f27f667

Files changed

benchmark/package.jsonchanged
benchmark/radixTree-lmza.jsadded
benchmark/package.jsonView
@@ -9,7 +9,8 @@
99 "author": "",
1010 "license": "ISC",
1111 "dependencies": {
1212 "borc": "^2.0.2",
13 + "lzma": "^2.3.2",
1314 "merkle-patricia-tree": "^2.2.0"
1415 }
1516 }
benchmark/radixTree-lmza.jsView
@@ -1,0 +1,67 @@
1 +const IPFS = require('ipfs')
2 +const crypto = require('crypto')
3 +const RadixTree = require('../')
4 +const cbor = require('borc')
5 +const lzma = require('lzma')
6 +
7 +// start ipfs
8 +const node = new IPFS({
9 + start: false,
10 + repo: './ipfs-repo'
11 +})
12 +
13 +node.on('ready', async () => {
14 + const tree = new RadixTree({
15 + dag: node.dag,
16 + // root: { '/': 'zdpuAmHPs6YDFyFoaUHg5YgyNHoUGKzug5n5ZzdjUrk36Gnzg'}
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 + const root = tree.root
32 +
33 + for (let i = 0; i < entries; i++) {
34 + const tree = new RadixTree({
35 + dag: node.dag,
36 + root: {'/': root['/']}
37 + })
38 + const key = crypto.createHash('sha256').update(i.toString()).digest().slice(0, 20)
39 + await tree.get(key)
40 + removeLink(tree.root['/'])
41 + const encoded = cbor.encode(tree.root['/'])
42 + proofSize += encoded.length
43 + compressedSize += lzma.compress(encoded, 9).length
44 + }
45 + console.log('cbor size', proofSize / entries)
46 + console.log('compressed size', compressedSize / entries)
47 +})
48 +
49 +function removeLink (root) {
50 + if (root) {
51 + if (root[0]) {
52 + root[0] = root[0]['/']
53 + }
54 +
55 + if (root[1]) {
56 + root[1] = root[1]['/']
57 + }
58 +
59 + if (!Buffer.isBuffer(root[1])) {
60 + removeLink(root[1])
61 + }
62 +
63 + if (!Buffer.isBuffer(root[0])) {
64 + removeLink(root[0])
65 + }
66 + }
67 +}

Built with git-ssb-web