UNPKG

945 BJavaScriptView Raw
1/*
2on rvagg@fletcher:
3 @0.2.3: Ran 36719 iterations in 10000 ms
4*/
5
6const through2 = require('../')
7 , bl = require('bl')
8 , crypto = require('crypto')
9 , assert = require('assert')
10
11function 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
29var 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
42console.log('Running for ~10s')
\No newline at end of file