git ssb

3+

cel / ssb-npm-registry



Tree: 4f27567900a7b5b821bccc74e95bfc96c8233159

Files: 4f27567900a7b5b821bccc74e95bfc96c8233159 / node_modules / pull-file / examples / bench.js

1423 bytesRaw
1
2var Stats = require('statistics')
3var cont = require('cont')
4
5function bench (a, b, N) {
6
7 N = N || 20,n = N
8 var sA = Stats(), sB = Stats()
9 var results_a = [], results_b = []
10 var A, B
11
12 var wins = 0
13
14 ;(function next () {
15
16 cont.series([
17 function (cb) {
18 a(function (err, data) {
19 var time = data.time/1000
20 var size = data.total/(1024*1024)
21 sA.value(size/time) //bytes per ms
22 results_a.push(A = data)
23 cb()
24
25 })
26 },
27 function (cb) {
28 b(function (err, data) {
29 var time = data.time/1000
30 var size = data.total/(1024*1024)
31 sB.value(size/time) //bytes per ms
32 results_b.push(B = data)
33 cb()
34 })
35 }
36 ].sort(function () {
37 return Math.random() - 0.5
38 }))(function (err) {
39 if(A.time < B.time)
40 wins ++
41
42 console.log('winner:', A.time < B.time ? 'A' : 'B', A, B)
43
44 if(0<--n) next()
45 else {
46 console.log('A: pull-stream')
47 console.log(sA.toJSON())
48 console.log('B: node stream')
49 console.log(sB.toJSON())
50 console.log('chance A wins:', wins/N, wins, N - wins)
51 }
52 })
53 })()
54
55}
56
57if(!module.parent) {
58 var file = process.argv[2]
59 var pull = require('./rate')
60 var node = require('./node-rate')
61 bench(function (cb) {
62 pull(file, cb)
63 }, function (cb) {
64 node(file, cb)
65 })
66
67}
68
69
70
71
72
73
74
75

Built with git-ssb-web