Skip to content

Commit

Permalink
fixup: avoid socket alloc
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Jan 5, 2022
1 parent 16a7034 commit e9a4ca2
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions bench/bench.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import cronometro from 'cronometro';
const server = net
.createServer((socket) => {
socket.resume();
socket.on('error', () => {});
})
.listen(0);
const socket = net.connect(server.address().port, '0.0.0.0');

function toBuffer(data) {
toBuffer.readOnly = true;
Expand Down Expand Up @@ -53,37 +53,22 @@ function toBuffer2(data) {
cronometro(
{
string(cb) {
const socket = net.connect(server.address().port, '0.0.0.0');
for (let n = 0; n < 16; ++n) {
socket.write(Buffer.allocUnsafe(4096).toString());
}
socket.end();
socket.on('finish', () => {
socket.on('error', () => {}).destroy();
cb();
});
socket.write('eof', cb);
},
toBuffer(cb) {
const socket = net.connect(server.address().port, '0.0.0.0');
for (let n = 0; n < 16; ++n) {
socket.write(toBuffer(Buffer.allocUnsafe(4096).toString()));
}
socket.end();
socket.on('finish', () => {
socket.on('error', () => {}).destroy();
cb();
});
socket.write('eof', cb);
},
toBuffer2(cb) {
const socket = net.connect(server.address().port, '0.0.0.0');
for (let n = 0; n < 16; ++n) {
socket.write(toBuffer2(Buffer.allocUnsafe(4096).toString()));
}
socket.end();
socket.on('finish', () => {
socket.on('error', () => {}).destroy();
cb();
});
socket.write('eof', cb);
}
},
{
Expand Down

0 comments on commit e9a4ca2

Please sign in to comment.