Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Jan 5, 2022
1 parent 02bd377 commit 0555b10
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions bench/bench.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,34 @@ function toBuffer(data) {
return buf;
}

function toBuffer2(data) {
if (typeof data === 'string') {
toBuffer.readOnly = false;
return Buffer.from(data);
}
toBuffer.readOnly = true;

if (Buffer.isBuffer(data)) return data;

let buf;

if (data instanceof ArrayBuffer) {
buf = Buffer.from(data);
} else if (ArrayBuffer.isView(data)) {
buf = Buffer.from(data.buffer, data.byteOffset, data.byteLength);
} else {
buf = Buffer.from(data);
toBuffer.readOnly = false;
}

return buf;
}

cronometro(
{
string(cb) {
const socket = net.connect(server.address().port, '0.0.0.0');
for (let n = 0; n < 1024; ++n) {
for (let n = 0; n < 16; ++n) {
socket.write(Buffer.allocUnsafe(4096).toString());
}
socket.end();
Expand All @@ -42,7 +65,18 @@ cronometro(
},
toBuffer(cb) {
const socket = net.connect(server.address().port, '0.0.0.0');
for (let n = 0; n < 1024; ++n) {
for (let n = 0; n < 16; ++n) {
socket.write(toBuffer(Buffer.allocUnsafe(4096).toString()));
}
socket.end();
socket.on('finish', () => {
socket.on('error', () => {}).destroy();
cb();
});
},
toBuffer2(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();
Expand All @@ -53,7 +87,7 @@ cronometro(
}
},
{
iterations: 100,
iterations: 1000,
print: { compare: true }
},
(err, results) => {
Expand Down

0 comments on commit 0555b10

Please sign in to comment.