forked from ssbc/bench-ssb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path06-ssb-read.js
36 lines (32 loc) · 948 Bytes
/
06-ssb-read.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
var SSB = require('secure-scuttlebutt')
var Paramap = require('pull-paramap')
var pull = require('pull-stream')
var db = SSB(null, {}, null, '/tmp/bench-ssb-legacy_ssb/')
db.ready.set(true)
var pull = require('pull-stream')
var a = []
pull(
// db.createLogStream({reverse: true, keys: true, values: false, meta: true}),
db.time.read({keys: true, values: false}),
pull.collect(function (err, ary) {
ary.sort(function () { return Math.random() - 0.5 })
var log = require('./util')('random-read')
pull(
pull.count(100000-1),
pull.map(function () {
var r = Math.random()
//return ary[~~( (1/(r*100000))*100000 )]
return ary[~~(Math.pow(Math.random(), 10)*ary.length)]
}),
pull.filter(Boolean),
Paramap(function (k, cb) {
db.get(k.seq, cb)
}, 100),
pull.drain(function (msg) {
log(1)
}, function () {
log(0, true)
})
)
})
)