1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | const through2 = require('../')
|
7 | , bl = require('bl')
|
8 | , crypto = require('crypto')
|
9 | , assert = require('assert')
|
10 |
|
11 | function run (callback) {
|
12 | var bufs = Array.apply(null, Array(10)).map(function () { return crypto.randomBytes(32) })
|
13 | , stream = through2(function (chunk, env, callback) {
|
14 | callback(null, chunk.toString('hex'))
|
15 | })
|
16 |
|
17 | stream.pipe(bl(function (err, data) {
|
18 | assert(!err)
|
19 | assert.equal(data.toString(), Buffer.concat(bufs).toString('hex'))
|
20 | callback()
|
21 | }))
|
22 |
|
23 | bufs.forEach(function (b) {
|
24 | stream.write(b)
|
25 | })
|
26 | stream.end()
|
27 | }
|
28 |
|
29 | var count = 0
|
30 | , start = Date.now()
|
31 |
|
32 | ;(function exec () {
|
33 | count++
|
34 | run(function () {
|
35 | if (Date.now() - start < 1000 * 10) {
|
36 | return setImmediate(exec)
|
37 | }
|
38 | console.log('Ran', count, 'iterations in', Date.now() - start, 'ms')
|
39 | })
|
40 | }())
|
41 |
|
42 | console.log('Running for ~10s') |
\ | No newline at end of file |