summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2018-08-15 17:14:22 -0700
committerJames M Snell <jasnell@gmail.com>2018-08-19 12:46:10 -0700
commit884b23daf723db60ebe939e6dde492fa5f9230eb (patch)
treefeb159647324b4fd00024d72ea464cd4cbe161ab /benchmark
parent7108893ec8fb3b3ee8538c82640fa61ac7014e38 (diff)
downloadandroid-node-v8-884b23daf723db60ebe939e6dde492fa5f9230eb.tar.gz
android-node-v8-884b23daf723db60ebe939e6dde492fa5f9230eb.tar.bz2
android-node-v8-884b23daf723db60ebe939e6dde492fa5f9230eb.zip
stream: move process.binding('stream_wrap') to internalBinding
PR-URL: https://github.com/nodejs/node/pull/22345 Refs: https://github.com/nodejs/node/issues/22160 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/net/tcp-raw-c2s.js114
-rw-r--r--benchmark/net/tcp-raw-pipe.js21
-rw-r--r--benchmark/net/tcp-raw-s2c.js81
3 files changed, 111 insertions, 105 deletions
diff --git a/benchmark/net/tcp-raw-c2s.js b/benchmark/net/tcp-raw-c2s.js
index 4b6dd9c3f2..d6666011d5 100644
--- a/benchmark/net/tcp-raw-c2s.js
+++ b/benchmark/net/tcp-raw-c2s.js
@@ -12,14 +12,15 @@ const bench = common.createBenchmark(main, {
len: [102400, 1024 * 1024 * 16],
type: ['utf', 'asc', 'buf'],
dur: [5]
-});
-
-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;
+}, { flags: [ '--expose-internals', '--no-warnings' ] });
function main({ dur, len, type }) {
+ const { internalBinding } = require('internal/test/binding');
+ const { TCP, constants: TCPConstants } = process.binding('tcp_wrap');
+ const { TCPConnectWrap } = process.binding('tcp_wrap');
+ const { WriteWrap } = internalBinding('stream_wrap');
+ const PORT = common.PORT;
+
const serverHandle = new TCP(TCPConstants.SERVER);
var err = serverHandle.bind('127.0.0.1', PORT);
if (err)
@@ -58,71 +59,70 @@ function main({ dur, len, type }) {
};
client(type, len);
-}
-
-function fail(err, syscall) {
- throw util._errnoException(err, syscall);
-}
-
-function client(type, len) {
- var chunk;
- switch (type) {
- case 'buf':
- chunk = Buffer.alloc(len, 'x');
- break;
- case 'utf':
- chunk = 'ü'.repeat(len / 2);
- break;
- case 'asc':
- chunk = 'x'.repeat(len);
- break;
- default:
- throw new Error(`invalid type: ${type}`);
+ function fail(err, syscall) {
+ throw util._errnoException(err, syscall);
}
- const clientHandle = new TCP(TCPConstants.SOCKET);
- const connectReq = new TCPConnectWrap();
- const err = clientHandle.connect(connectReq, '127.0.0.1', PORT);
-
- if (err)
- fail(err, 'connect');
-
- clientHandle.readStart();
-
- connectReq.oncomplete = function(err) {
- if (err)
- fail(err, 'connect');
-
- while (clientHandle.writeQueueSize === 0)
- write();
- };
-
- function write() {
- const writeReq = new WriteWrap();
- writeReq.oncomplete = afterWrite;
- var err;
+ function client(type, len) {
+ var chunk;
switch (type) {
case 'buf':
- err = clientHandle.writeBuffer(writeReq, chunk);
+ chunk = Buffer.alloc(len, 'x');
break;
case 'utf':
- err = clientHandle.writeUtf8String(writeReq, chunk);
+ chunk = 'ü'.repeat(len / 2);
break;
case 'asc':
- err = clientHandle.writeAsciiString(writeReq, chunk);
+ chunk = 'x'.repeat(len);
break;
+ default:
+ throw new Error(`invalid type: ${type}`);
}
- if (err)
- fail(err, 'write');
- }
+ const clientHandle = new TCP(TCPConstants.SOCKET);
+ const connectReq = new TCPConnectWrap();
+ const err = clientHandle.connect(connectReq, '127.0.0.1', PORT);
- function afterWrite(err, handle) {
if (err)
- fail(err, 'write');
+ fail(err, 'connect');
+
+ clientHandle.readStart();
+
+ connectReq.oncomplete = function(err) {
+ if (err)
+ fail(err, 'connect');
- while (clientHandle.writeQueueSize === 0)
- write();
+ while (clientHandle.writeQueueSize === 0)
+ write();
+ };
+
+ function write() {
+ const writeReq = new WriteWrap();
+ writeReq.oncomplete = afterWrite;
+ var err;
+ switch (type) {
+ case 'buf':
+ err = clientHandle.writeBuffer(writeReq, chunk);
+ break;
+ case 'utf':
+ err = clientHandle.writeUtf8String(writeReq, chunk);
+ break;
+ case 'asc':
+ err = clientHandle.writeAsciiString(writeReq, chunk);
+ break;
+ }
+
+ if (err)
+ fail(err, 'write');
+ }
+
+ function afterWrite(err, handle) {
+ if (err)
+ fail(err, 'write');
+
+ while (clientHandle.writeQueueSize === 0)
+ write();
+ }
}
}
diff --git a/benchmark/net/tcp-raw-pipe.js b/benchmark/net/tcp-raw-pipe.js
index dfde3d40b5..8203abca6e 100644
--- a/benchmark/net/tcp-raw-pipe.js
+++ b/benchmark/net/tcp-raw-pipe.js
@@ -12,18 +12,21 @@ const bench = common.createBenchmark(main, {
len: [102400, 1024 * 1024 * 16],
type: ['utf', 'asc', 'buf'],
dur: [5]
+}, {
+ flags: [ '--expose-internals', '--no-warnings' ]
});
-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;
-
function main({ dur, len, type }) {
+ const { internalBinding } = require('internal/test/binding');
+ const { TCP, constants: TCPConstants } = process.binding('tcp_wrap');
+ const { TCPConnectWrap } = process.binding('tcp_wrap');
+ const { WriteWrap } = internalBinding('stream_wrap');
+ const PORT = common.PORT;
+
+ function fail(err, syscall) {
+ throw util._errnoException(err, syscall);
+ }
+
// Server
const serverHandle = new TCP(TCPConstants.SERVER);
var err = serverHandle.bind('127.0.0.1', PORT);
diff --git a/benchmark/net/tcp-raw-s2c.js b/benchmark/net/tcp-raw-s2c.js
index fe0bffd812..1e42b311ad 100644
--- a/benchmark/net/tcp-raw-s2c.js
+++ b/benchmark/net/tcp-raw-s2c.js
@@ -12,14 +12,17 @@ const bench = common.createBenchmark(main, {
len: [102400, 1024 * 1024 * 16],
type: ['utf', 'asc', 'buf'],
dur: [5]
+}, {
+ flags: [ '--expose-internals', '--no-warnings' ]
});
-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;
-
function main({ dur, len, type }) {
+ const { internalBinding } = require('internal/test/binding');
+ const { TCP, constants: TCPConstants } = process.binding('tcp_wrap');
+ const { TCPConnectWrap } = process.binding('tcp_wrap');
+ const { WriteWrap } = internalBinding('stream_wrap');
+ const PORT = common.PORT;
+
const serverHandle = new TCP(TCPConstants.SERVER);
var err = serverHandle.bind('127.0.0.1', PORT);
if (err)
@@ -89,42 +92,42 @@ function main({ dur, len, type }) {
};
client(dur);
-}
-function fail(err, syscall) {
- throw util._errnoException(err, syscall);
-}
+ function fail(err, syscall) {
+ throw util._errnoException(err, syscall);
+ }
-function client(dur) {
- const clientHandle = new TCP(TCPConstants.SOCKET);
- const connectReq = new TCPConnectWrap();
- const err = clientHandle.connect(connectReq, '127.0.0.1', PORT);
-
- if (err)
- fail(err, 'connect');
-
- connectReq.oncomplete = function() {
- var bytes = 0;
- clientHandle.onread = function(nread, buffer) {
- // we're not expecting to ever get an EOF from the client.
- // just lots of data forever.
- if (nread < 0)
- fail(nread, 'read');
-
- // don't slice the buffer. the point of this is to isolate, not
- // simulate real traffic.
- bytes += buffer.length;
- };
+ function client(dur) {
+ const clientHandle = new TCP(TCPConstants.SOCKET);
+ const connectReq = new TCPConnectWrap();
+ const err = clientHandle.connect(connectReq, '127.0.0.1', PORT);
- clientHandle.readStart();
-
- // the meat of the benchmark is right here:
- bench.start();
+ if (err)
+ fail(err, 'connect');
- setTimeout(function() {
- // report in Gb/sec
- bench.end((bytes * 8) / (1024 * 1024 * 1024));
- process.exit(0);
- }, dur * 1000);
- };
+ connectReq.oncomplete = function() {
+ var bytes = 0;
+ clientHandle.onread = function(nread, buffer) {
+ // we're not expecting to ever get an EOF from the client.
+ // just lots of data forever.
+ if (nread < 0)
+ fail(nread, 'read');
+
+ // don't slice the buffer. the point of this is to isolate, not
+ // simulate real traffic.
+ bytes += buffer.length;
+ };
+
+ clientHandle.readStart();
+
+ // the meat of the benchmark is right here:
+ bench.start();
+
+ setTimeout(function() {
+ // report in Gb/sec
+ bench.end((bytes * 8) / (1024 * 1024 * 1024));
+ process.exit(0);
+ }, dur * 1000);
+ };
+ }
}