Skip to content

Instantly share code, notes, and snippets.

@serby
Created February 15, 2016 14:24
Show Gist options
  • Save serby/ea40262989018c375dcb to your computer and use it in GitHub Desktop.
Save serby/ea40262989018c375dcb to your computer and use it in GitHub Desktop.
const size = 74 * 1024
var packet = { name: 'Paul Serby', email: 'paul.serby@clock.co.uk' }
, packetSize = JSON.stringify(packet).length
, count = Math.round(size / packetSize)
, buffer = []
, i
, time = Date.now()
, bigPacket = Array(size).fill('X')
for (i = 0; i < count; i++) {
packet.random = Math.random()
buffer.push(JSON.stringify(packet))
}
for (i = 0; i < count; i++) {
process.stderr.write(buffer[i])
}
console.log('\n\nSmall packets %d x %d bytes (total: %d bytes) in %dms'
, count, packetSize, count * packetSize, Date.now() - time)
time = Date.now()
process.stderr.write(JSON.stringify(bigPacket))
console.log('Single write of %d bytes in %dms', size, Date.now() - time)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment