forked from mafintosh/length-prefixed-stream
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.js
More file actions
25 lines (20 loc) · 657 Bytes
/
benchmark.js
File metadata and controls
25 lines (20 loc) · 657 Bytes
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
const stream = require('readable-stream')
const encode = require('./encode')
const decode = require('./decode')
const bufferAlloc = require('buffer-alloc')
const buf = bufferAlloc(32 * 1024)
const source = new stream.Readable()
let sent = 0
source._read = function () {
if (sent > 5 * 1024 * 1024 * 1024) return source.push(null)
sent += buf.length
source.push(buf)
}
// silly benchmark that allows me to look for opts/deopts
const s = source.pipe(encode()).pipe(decode())
const now = Date.now()
s.resume()
s.on('end', function () {
const delta = Date.now() - now
console.log('%d b/s (%d)', Math.floor(100000 * sent / delta) / 100, delta)
})