git ssb

6+

Dominic / epidemic-broadcast-trees



Commit 8ade9e96623590632cad036bb2ebba67b35ecb5e

basic benchmark

Dominic Tarr committed on 4/15/2017, 6:00:42 AM
Parent: 01bba10b6cd6df4e2aab9bc81b5f4766d42699e6

Files changed

test/bench.jsadded
test/bench.jsView
@@ -1,0 +1,100 @@
1 +var pull = require('pull-stream')
2 +var ex = require('../example')
3 +
4 +//var model_a = ex.create()
5 +
6 +
7 +var tape = require('tape')
8 +
9 +tape('simple', function (t) {
10 + var alice = ex.createChatModel('alice', [])
11 + var bob = ex.createChatModel('bob')
12 +
13 + var as = ex.createStream(alice)
14 + var bs = ex.createStream(bob)
15 +
16 + pull(as, bs, as)
17 +
18 + var msg = {author: 'alice', sequence: 1, content: 'hello bob!', timestamp: Date.now()}
19 +
20 + //have bob get ready to receive something
21 + bob.onAppend(function (_msg) {
22 + console.log('msg at bob:', _msg)
23 + t.deepEqual(_msg, msg)
24 + t.end()
25 + })
26 +
27 + //have alice send a message to bob
28 + alice.append(msg)
29 +
30 +})
31 +
32 +function init(model, N, M) {
33 + for(var i = 0; i < N; i++)
34 + model.logs['peer'+i] = []
35 +
36 + for(var i = 0; i < M; i++) {
37 + var k = 'peer'+~~(Math.random()*N)
38 + model.logs[k].push({
39 + author: k, sequence: model.logs[k].length + 1, content: 'hello:'+Math.random()
40 + })
41 + }
42 +}
43 +
44 +tape('simple', function (t) {
45 + var alice = ex.createChatModel()
46 + var bob = ex.createChatModel()
47 +
48 + init(alice, 10, 100)
49 +
50 + var as = ex.createStream(alice)
51 + var bs = ex.createStream(bob)
52 +
53 + function log(name) {
54 + return pull.through(function (data) {
55 + console.log(name, data)
56 + })
57 + }
58 +
59 + pull(as, bs, as)
60 +
61 + //because everything is sync, it should be complete already.
62 +
63 + t.deepEqual(bob.logs, alice.logs)
64 + t.end()
65 +// console.log(alice.logs)
66 +})
67 +
68 +
69 +tape('simple', function (t) {
70 + var alice = ex.createChatModel()
71 + var bob = ex.createChatModel()
72 +
73 + init(alice, 1000, 10000)
74 +
75 + var as = ex.createStream(alice)
76 + var bs = ex.createStream(bob)
77 +
78 + function log(name) {
79 + return pull.through(function (data) {
80 + console.log(name, data)
81 + })
82 + }
83 + var c = 0, start = Date.now()
84 + bob.onAppend(function () {
85 + if(!(c++ % 1000))
86 + console.log(c, Date.now() - start)
87 + })
88 +
89 + pull(as, bs, as)
90 +
91 + //because everything is sync, it should be complete already.
92 +
93 + var seconds = ((Date.now() - start)/1000)
94 + console.log(c, seconds, c / seconds, T)
95 +
96 + t.deepEqual(bob.logs, alice.logs)
97 + t.end()
98 +// console.log(alice.logs)
99 +})
100 +

Built with git-ssb-web