-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbenchmark.js
49 lines (38 loc) · 1005 Bytes
/
benchmark.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var connectionString = 'postgres://postgres:@localhost:5432/pgipc'
var pg = require('pg')
var ipc = require('.')
var stats = require('statistics')
var speedometer = require('speedometer')
var assert = require('assert')
var client = new pg.Client(connectionString)
client.connect(assert.ifError)
var ee = ipc(client)
ee.once('error', assert.ifError)
ee.once('end', function () {
client.end()
})
var speed = speedometer(10)
if (process.argv[2] === 'SOURCE') {
ee.on('notify', function () {
console.log('Source: ', speed(1))
})
for (var i = 0; i < 10000; i++) {
ee.notify('channel', {sent: Date.now()})
}
client.on('drain', function () {
ee.end()
})
}
if (process.argv[2] === 'SINK') {
var deltas = []
ee.on('channel', function (msg) {
console.log('Sink: ', speed(1))
deltas.push(Date.now() - msg.payload.sent)
if (deltas.length > 9999) {
ee.end()
}
})
ee.prependOnceListener('end', function () {
console.log(deltas.reduce(stats))
})
}