var PacketStream = require('../')
var N = 100000

N = +process.argv[2] || N

var replies = []
var a = new PacketStream({})
var b = new PacketStream({
  request: function (opts, cb) {
//    console.log('request:', opts)
    replies.push({value: opts, cb: cb})
  },
  close: function () {}
})

a.read = function (data, end) {
//  console.log('a.read', data, end)
  b.write(data, end)
}
b.read = function (data, end) {
//  console.log('b.read', data, end)
  a.write(data, end)
}

var start = Date.now()
var heap = process.memoryUsage().heapUsed
for(var i = 0; i < N; i++)
  a.request(Math.random(), function () {})

console.log((Date.now()-start)/N, (process.memoryUsage().heapUsed - heap)/N)

for(var i = 0; i < replies.length; i++)
  replies[i].cb(null, replies[i].value)
replies = null

console.log((Date.now()-start)/N, (process.memoryUsage().heapUsed - heap)/N)


