summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorBrian White <mscdex@mscdex.net>2019-01-10 15:52:27 -0500
committerBrian White <mscdex@mscdex.net>2019-08-23 17:05:52 -0400
commit8292b280ec9e6b8c2444cbe49350facc77f5fefa (patch)
tree2f40ac41f20b53b748a7039c4f00e419efb8784b /benchmark
parent9d21b0395cc248a0e5537a11cc84f61919eccca6 (diff)
downloadandroid-node-v8-8292b280ec9e6b8c2444cbe49350facc77f5fefa.tar.gz
android-node-v8-8292b280ec9e6b8c2444cbe49350facc77f5fefa.tar.bz2
android-node-v8-8292b280ec9e6b8c2444cbe49350facc77f5fefa.zip
net: allow reading data into a static buffer
Co-Authored-By: Anna Henningsen <anna@addaleax.net> PR-URL: https://github.com/nodejs/node/pull/25436 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/net/net-s2c.js57
1 files changed, 46 insertions, 11 deletions
diff --git a/benchmark/net/net-s2c.js b/benchmark/net/net-s2c.js
index e3c5c7e5eb..d8c26db9bd 100644
--- a/benchmark/net/net-s2c.js
+++ b/benchmark/net/net-s2c.js
@@ -5,33 +5,68 @@ const common = require('../common.js');
const PORT = common.PORT;
const bench = common.createBenchmark(main, {
- len: [64, 102400, 1024 * 1024 * 16],
+ sendchunklen: [256, 32 * 1024, 128 * 1024, 16 * 1024 * 1024],
type: ['utf', 'asc', 'buf'],
+ recvbuflen: [0, 64 * 1024, 1024 * 1024],
+ recvbufgenfn: ['true', 'false'],
dur: [5]
});
var chunk;
var encoding;
+var recvbuf;
+var received = 0;
+
+function main({ dur, sendchunklen, type, recvbuflen, recvbufgenfn }) {
+ if (isFinite(recvbuflen) && recvbuflen > 0)
+ recvbuf = Buffer.alloc(recvbuflen);
-function main({ dur, len, type }) {
switch (type) {
case 'buf':
- chunk = Buffer.alloc(len, 'x');
+ chunk = Buffer.alloc(sendchunklen, 'x');
break;
case 'utf':
encoding = 'utf8';
- chunk = 'ü'.repeat(len / 2);
+ chunk = 'ü'.repeat(sendchunklen / 2);
break;
case 'asc':
encoding = 'ascii';
- chunk = 'x'.repeat(len);
+ chunk = 'x'.repeat(sendchunklen);
break;
default:
throw new Error(`invalid type: ${type}`);
}
const reader = new Reader();
- const writer = new Writer();
+ var writer;
+ var socketOpts;
+ if (recvbuf === undefined) {
+ writer = new Writer();
+ socketOpts = { port: PORT };
+ } else {
+ let buffer = recvbuf;
+ if (recvbufgenfn === 'true') {
+ let bufidx = -1;
+ const bufpool = [
+ recvbuf,
+ Buffer.from(recvbuf),
+ Buffer.from(recvbuf),
+ ];
+ buffer = () => {
+ bufidx = (bufidx + 1) % bufpool.length;
+ return bufpool[bufidx];
+ };
+ }
+ socketOpts = {
+ port: PORT,
+ onread: {
+ buffer,
+ callback: function(nread, buf) {
+ received += nread;
+ }
+ }
+ };
+ }
// The actual benchmark.
const server = net.createServer((socket) => {
@@ -39,14 +74,15 @@ function main({ dur, len, type }) {
});
server.listen(PORT, () => {
- const socket = net.connect(PORT);
+ const socket = net.connect(socketOpts);
socket.on('connect', () => {
bench.start();
- socket.pipe(writer);
+ if (recvbuf === undefined)
+ socket.pipe(writer);
setTimeout(() => {
- const bytes = writer.received;
+ const bytes = received;
const gbits = (bytes * 8) / (1024 * 1024 * 1024);
bench.end(gbits);
process.exit(0);
@@ -58,12 +94,11 @@ function main({ dur, len, type }) {
const net = require('net');
function Writer() {
- this.received = 0;
this.writable = true;
}
Writer.prototype.write = function(chunk, encoding, cb) {
- this.received += chunk.length;
+ received += chunk.length;
if (typeof encoding === 'function')
encoding();