summaryrefslogtreecommitdiff
path: root/benchmark/net
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2017-12-30 03:56:44 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2018-01-23 01:29:23 +0100
commit19bdfa53804918a0da5b5e4771dfc7761dc21274 (patch)
treee69d379765724d95672a950b3ca301f353885c97 /benchmark/net
parentd163a6b8c2ff98a00581a7c62fad9d2232cbb1a9 (diff)
downloadandroid-node-v8-19bdfa53804918a0da5b5e4771dfc7761dc21274.tar.gz
android-node-v8-19bdfa53804918a0da5b5e4771dfc7761dc21274.tar.bz2
android-node-v8-19bdfa53804918a0da5b5e4771dfc7761dc21274.zip
benchmark: (net) use destructuring
PR-URL: https://github.com/nodejs/node/pull/18250 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'benchmark/net')
-rw-r--r--benchmark/net/net-c2s-cork.js60
-rw-r--r--benchmark/net/net-c2s.js63
-rw-r--r--benchmark/net/net-pipe.js69
-rw-r--r--benchmark/net/net-s2c.js60
-rw-r--r--benchmark/net/net-wrap-js-stream-passthrough.js47
-rw-r--r--benchmark/net/tcp-raw-c2s.js27
-rw-r--r--benchmark/net/tcp-raw-pipe.js29
-rw-r--r--benchmark/net/tcp-raw-s2c.js25
8 files changed, 142 insertions, 238 deletions
diff --git a/benchmark/net/net-c2s-cork.js b/benchmark/net/net-c2s-cork.js
index a6582caa16..55bb99f6f7 100644
--- a/benchmark/net/net-c2s-cork.js
+++ b/benchmark/net/net-c2s-cork.js
@@ -2,6 +2,7 @@
'use strict';
const common = require('../common.js');
+const net = require('net');
const PORT = common.PORT;
const bench = common.createBenchmark(main, {
@@ -10,17 +11,10 @@ const bench = common.createBenchmark(main, {
dur: [5],
});
-var dur;
-var len;
-var type;
var chunk;
var encoding;
-function main(conf) {
- dur = +conf.dur;
- len = +conf.len;
- type = conf.type;
-
+function main({ dur, len, type }) {
switch (type) {
case 'buf':
chunk = Buffer.alloc(len, 'x');
@@ -37,34 +31,6 @@ function main(conf) {
throw new Error(`invalid type: ${type}`);
}
- server();
-}
-
-const net = require('net');
-
-function Writer() {
- this.received = 0;
- this.writable = true;
-}
-
-Writer.prototype.write = function(chunk, encoding, cb) {
- this.received += chunk.length;
-
- if (typeof encoding === 'function')
- encoding();
- else if (typeof cb === 'function')
- cb();
-
- return true;
-};
-
-// doesn't matter, never emits anything.
-Writer.prototype.on = function() {};
-Writer.prototype.once = function() {};
-Writer.prototype.emit = function() {};
-Writer.prototype.prependListener = function() {};
-
-function server() {
const writer = new Writer();
// the actual benchmark.
@@ -95,3 +61,25 @@ function server() {
});
});
}
+
+function Writer() {
+ this.received = 0;
+ this.writable = true;
+}
+
+Writer.prototype.write = function(chunk, encoding, cb) {
+ this.received += chunk.length;
+
+ if (typeof encoding === 'function')
+ encoding();
+ else if (typeof cb === 'function')
+ cb();
+
+ return true;
+};
+
+// doesn't matter, never emits anything.
+Writer.prototype.on = function() {};
+Writer.prototype.once = function() {};
+Writer.prototype.emit = function() {};
+Writer.prototype.prependListener = function() {};
diff --git a/benchmark/net/net-c2s.js b/benchmark/net/net-c2s.js
index 140f9612ab..4add79a166 100644
--- a/benchmark/net/net-c2s.js
+++ b/benchmark/net/net-c2s.js
@@ -2,6 +2,7 @@
'use strict';
const common = require('../common.js');
+const net = require('net');
const PORT = common.PORT;
const bench = common.createBenchmark(main, {
@@ -10,17 +11,10 @@ const bench = common.createBenchmark(main, {
dur: [5],
});
-var dur;
-var len;
-var type;
var chunk;
var encoding;
-function main(conf) {
- dur = +conf.dur;
- len = +conf.len;
- type = conf.type;
-
+function main({ dur, len, type }) {
switch (type) {
case 'buf':
chunk = Buffer.alloc(len, 'x');
@@ -37,10 +31,30 @@ function main(conf) {
throw new Error(`invalid type: ${type}`);
}
- server();
-}
+ const reader = new Reader();
+ const writer = new Writer();
-const net = require('net');
+ // the actual benchmark.
+ const server = net.createServer(function(socket) {
+ socket.pipe(writer);
+ });
+
+ server.listen(PORT, function() {
+ const socket = net.connect(PORT);
+ socket.on('connect', function() {
+ bench.start();
+
+ reader.pipe(socket);
+
+ setTimeout(function() {
+ const bytes = writer.received;
+ const gbits = (bytes * 8) / (1024 * 1024 * 1024);
+ bench.end(gbits);
+ process.exit(0);
+ }, dur * 1000);
+ });
+ });
+}
function Writer() {
this.received = 0;
@@ -84,30 +98,3 @@ Reader.prototype.pipe = function(dest) {
this.flow();
return dest;
};
-
-
-function server() {
- const reader = new Reader();
- const writer = new Writer();
-
- // the actual benchmark.
- const server = net.createServer(function(socket) {
- socket.pipe(writer);
- });
-
- server.listen(PORT, function() {
- const socket = net.connect(PORT);
- socket.on('connect', function() {
- bench.start();
-
- reader.pipe(socket);
-
- setTimeout(function() {
- const bytes = writer.received;
- const gbits = (bytes * 8) / (1024 * 1024 * 1024);
- bench.end(gbits);
- process.exit(0);
- }, dur * 1000);
- });
- });
-}
diff --git a/benchmark/net/net-pipe.js b/benchmark/net/net-pipe.js
index a8ae50edfb..3dd3bb78cc 100644
--- a/benchmark/net/net-pipe.js
+++ b/benchmark/net/net-pipe.js
@@ -2,6 +2,7 @@
'use strict';
const common = require('../common.js');
+const net = require('net');
const PORT = common.PORT;
const bench = common.createBenchmark(main, {
@@ -10,17 +11,10 @@ const bench = common.createBenchmark(main, {
dur: [5],
});
-var dur;
-var len;
-var type;
var chunk;
var encoding;
-function main(conf) {
- dur = +conf.dur;
- len = +conf.len;
- type = conf.type;
-
+function main({ dur, len, type }) {
switch (type) {
case 'buf':
chunk = Buffer.alloc(len, 'x');
@@ -37,10 +31,33 @@ function main(conf) {
throw new Error(`invalid type: ${type}`);
}
- server();
-}
+ const reader = new Reader();
+ const writer = new Writer();
-const net = require('net');
+ // the actual benchmark.
+ const server = net.createServer(function(socket) {
+ socket.pipe(socket);
+ });
+
+ server.listen(PORT, function() {
+ const socket = net.connect(PORT);
+ socket.on('connect', function() {
+ bench.start();
+
+ reader.pipe(socket);
+ socket.pipe(writer);
+
+ setTimeout(function() {
+ // multiply by 2 since we're sending it first one way
+ // then then back again.
+ const bytes = writer.received * 2;
+ const gbits = (bytes * 8) / (1024 * 1024 * 1024);
+ bench.end(gbits);
+ process.exit(0);
+ }, dur * 1000);
+ });
+ });
+}
function Writer() {
this.received = 0;
@@ -84,33 +101,3 @@ Reader.prototype.pipe = function(dest) {
this.flow();
return dest;
};
-
-
-function server() {
- const reader = new Reader();
- const writer = new Writer();
-
- // the actual benchmark.
- const server = net.createServer(function(socket) {
- socket.pipe(socket);
- });
-
- server.listen(PORT, function() {
- const socket = net.connect(PORT);
- socket.on('connect', function() {
- bench.start();
-
- reader.pipe(socket);
- socket.pipe(writer);
-
- setTimeout(function() {
- // multiply by 2 since we're sending it first one way
- // then then back again.
- const bytes = writer.received * 2;
- const gbits = (bytes * 8) / (1024 * 1024 * 1024);
- bench.end(gbits);
- process.exit(0);
- }, dur * 1000);
- });
- });
-}
diff --git a/benchmark/net/net-s2c.js b/benchmark/net/net-s2c.js
index 9fec2d8577..2ddf8fd6c5 100644
--- a/benchmark/net/net-s2c.js
+++ b/benchmark/net/net-s2c.js
@@ -10,17 +10,10 @@ const bench = common.createBenchmark(main, {
dur: [5]
});
-var dur;
-var len;
-var type;
var chunk;
var encoding;
-function main(conf) {
- dur = +conf.dur;
- len = +conf.len;
- type = conf.type;
-
+function main({ dur, len, type }) {
switch (type) {
case 'buf':
chunk = Buffer.alloc(len, 'x');
@@ -37,7 +30,29 @@ function main(conf) {
throw new Error(`invalid type: ${type}`);
}
- server();
+ const reader = new Reader();
+ const writer = new Writer();
+
+ // the actual benchmark.
+ const server = net.createServer(function(socket) {
+ reader.pipe(socket);
+ });
+
+ server.listen(PORT, function() {
+ const socket = net.connect(PORT);
+ socket.on('connect', function() {
+ bench.start();
+
+ socket.pipe(writer);
+
+ setTimeout(function() {
+ const bytes = writer.received;
+ const gbits = (bytes * 8) / (1024 * 1024 * 1024);
+ bench.end(gbits);
+ process.exit(0);
+ }, dur * 1000);
+ });
+ });
}
const net = require('net');
@@ -84,30 +99,3 @@ Reader.prototype.pipe = function(dest) {
this.flow();
return dest;
};
-
-
-function server() {
- const reader = new Reader();
- const writer = new Writer();
-
- // the actual benchmark.
- const server = net.createServer(function(socket) {
- reader.pipe(socket);
- });
-
- server.listen(PORT, function() {
- const socket = net.connect(PORT);
- socket.on('connect', function() {
- bench.start();
-
- socket.pipe(writer);
-
- setTimeout(function() {
- const bytes = writer.received;
- const gbits = (bytes * 8) / (1024 * 1024 * 1024);
- bench.end(gbits);
- process.exit(0);
- }, dur * 1000);
- });
- });
-}
diff --git a/benchmark/net/net-wrap-js-stream-passthrough.js b/benchmark/net/net-wrap-js-stream-passthrough.js
index bf84285e81..05a66f4e7a 100644
--- a/benchmark/net/net-wrap-js-stream-passthrough.js
+++ b/benchmark/net/net-wrap-js-stream-passthrough.js
@@ -12,18 +12,12 @@ const bench = common.createBenchmark(main, {
flags: ['--expose-internals']
});
-var dur;
-var len;
-var type;
var chunk;
var encoding;
-var JSStreamWrap; // Can only require internals inside main().
-function main(conf) {
- dur = +conf.dur;
- len = +conf.len;
- type = conf.type;
- JSStreamWrap = require('internal/wrap_js_stream');
+function main({ dur, len, type }) {
+ // Can only require internals inside main().
+ const JSStreamWrap = require('internal/wrap_js_stream');
switch (type) {
case 'buf':
@@ -41,7 +35,21 @@ function main(conf) {
throw new Error(`invalid type: ${type}`);
}
- doBenchmark();
+ const reader = new Reader();
+ const writer = new Writer();
+
+ // the actual benchmark.
+ const fakeSocket = new JSStreamWrap(new PassThrough());
+ bench.start();
+ reader.pipe(fakeSocket);
+ fakeSocket.pipe(writer);
+
+ setTimeout(function() {
+ const bytes = writer.received;
+ const gbits = (bytes * 8) / (1024 * 1024 * 1024);
+ bench.end(gbits);
+ process.exit(0);
+ }, dur * 1000);
}
function Writer() {
@@ -86,22 +94,3 @@ Reader.prototype.pipe = function(dest) {
this.flow();
return dest;
};
-
-
-function doBenchmark() {
- const reader = new Reader();
- const writer = new Writer();
-
- // the actual benchmark.
- const fakeSocket = new JSStreamWrap(new PassThrough());
- bench.start();
- reader.pipe(fakeSocket);
- fakeSocket.pipe(writer);
-
- setTimeout(function() {
- const bytes = writer.received;
- const gbits = (bytes * 8) / (1024 * 1024 * 1024);
- bench.end(gbits);
- process.exit(0);
- }, dur * 1000);
-}
diff --git a/benchmark/net/tcp-raw-c2s.js b/benchmark/net/tcp-raw-c2s.js
index bd41be8772..2be3bb3b53 100644
--- a/benchmark/net/tcp-raw-c2s.js
+++ b/benchmark/net/tcp-raw-c2s.js
@@ -19,23 +19,7 @@ const TCPConnectWrap = process.binding('tcp_wrap').TCPConnectWrap;
const WriteWrap = process.binding('stream_wrap').WriteWrap;
const PORT = common.PORT;
-var dur;
-var len;
-var type;
-
-function main(conf) {
- dur = +conf.dur;
- len = +conf.len;
- type = conf.type;
- server();
-}
-
-
-function fail(err, syscall) {
- throw util._errnoException(err, syscall);
-}
-
-function server() {
+function main({ dur, len, type }) {
const serverHandle = new TCP(TCPConstants.SERVER);
var err = serverHandle.bind('127.0.0.1', PORT);
if (err)
@@ -73,10 +57,15 @@ function server() {
clientHandle.readStart();
};
- client();
+ client(type, len);
+}
+
+
+function fail(err, syscall) {
+ throw util._errnoException(err, syscall);
}
-function client() {
+function client(type, len) {
var chunk;
switch (type) {
case 'buf':
diff --git a/benchmark/net/tcp-raw-pipe.js b/benchmark/net/tcp-raw-pipe.js
index 4dd06ed446..2fc03f08cd 100644
--- a/benchmark/net/tcp-raw-pipe.js
+++ b/benchmark/net/tcp-raw-pipe.js
@@ -14,27 +14,17 @@ const bench = common.createBenchmark(main, {
dur: [5]
});
+function fail(err, syscall) {
+ throw util._errnoException(err, syscall);
+}
+
const { TCP, constants: TCPConstants } = process.binding('tcp_wrap');
const TCPConnectWrap = process.binding('tcp_wrap').TCPConnectWrap;
const WriteWrap = process.binding('stream_wrap').WriteWrap;
const PORT = common.PORT;
-var dur;
-var len;
-var type;
-
-function main(conf) {
- dur = +conf.dur;
- len = +conf.len;
- type = conf.type;
- server();
-}
-
-function fail(err, syscall) {
- throw util._errnoException(err, syscall);
-}
-
-function server() {
+function main({ dur, len, type }) {
+ // Server
const serverHandle = new TCP(TCPConstants.SERVER);
var err = serverHandle.bind('127.0.0.1', PORT);
if (err)
@@ -70,10 +60,7 @@ function server() {
clientHandle.readStart();
};
- client();
-}
-
-function client() {
+ // Client
var chunk;
switch (type) {
case 'buf':
@@ -91,9 +78,9 @@ function client() {
const clientHandle = new TCP(TCPConstants.SOCKET);
const connectReq = new TCPConnectWrap();
- const err = clientHandle.connect(connectReq, '127.0.0.1', PORT);
var bytes = 0;
+ err = clientHandle.connect(connectReq, '127.0.0.1', PORT);
if (err)
fail(err, 'connect');
diff --git a/benchmark/net/tcp-raw-s2c.js b/benchmark/net/tcp-raw-s2c.js
index 2ca6016ce0..339f5e393d 100644
--- a/benchmark/net/tcp-raw-s2c.js
+++ b/benchmark/net/tcp-raw-s2c.js
@@ -19,22 +19,7 @@ const TCPConnectWrap = process.binding('tcp_wrap').TCPConnectWrap;
const WriteWrap = process.binding('stream_wrap').WriteWrap;
const PORT = common.PORT;
-var dur;
-var len;
-var type;
-
-function main(conf) {
- dur = +conf.dur;
- len = +conf.len;
- type = conf.type;
- server();
-}
-
-function fail(err, syscall) {
- throw util._errnoException(err, syscall);
-}
-
-function server() {
+function main({ dur, len, type }) {
const serverHandle = new TCP(TCPConstants.SERVER);
var err = serverHandle.bind('127.0.0.1', PORT);
if (err)
@@ -103,10 +88,14 @@ function server() {
}
};
- client();
+ client(dur);
+}
+
+function fail(err, syscall) {
+ throw util._errnoException(err, syscall);
}
-function client() {
+function client(dur) {
const clientHandle = new TCP(TCPConstants.SOCKET);
const connectReq = new TCPConnectWrap();
const err = clientHandle.connect(connectReq, '127.0.0.1', PORT);