Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

View File

@ -0,0 +1,85 @@
// Test the speed of .pipe() with sockets
'use strict';
const common = require('../common.js');
const net = require('net');
const PORT = common.PORT;
const bench = common.createBenchmark(main, {
len: [4, 8, 16, 32, 64, 128, 512, 1024],
type: ['buf'],
dur: [5],
});
let chunk;
let encoding;
function main({ dur, len, type }) {
switch (type) {
case 'buf':
chunk = Buffer.alloc(len, 'x');
break;
case 'utf':
encoding = 'utf8';
chunk = 'ü'.repeat(len / 2);
break;
case 'asc':
encoding = 'ascii';
chunk = 'x'.repeat(len);
break;
default:
throw new Error(`invalid type: ${type}`);
}
const writer = new Writer();
// The actual benchmark.
const server = net.createServer((socket) => {
socket.pipe(writer);
});
server.listen(PORT, () => {
const socket = net.connect(PORT);
socket.on('connect', () => {
bench.start();
socket.on('drain', send);
send();
setTimeout(() => {
const bytes = writer.received;
const gbits = (bytes * 8) / (1024 * 1024 * 1024);
bench.end(gbits);
process.exit(0);
}, dur * 1000);
function send() {
socket.cork();
while (socket.write(chunk, encoding));
socket.uncork();
}
});
});
}
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() {};

102
benchmark/net/net-c2s.js Normal file
View File

@ -0,0 +1,102 @@
// Test the speed of .pipe() with sockets
'use strict';
const common = require('../common.js');
const net = require('net');
const PORT = common.PORT;
const bench = common.createBenchmark(main, {
len: [64, 102400, 1024 * 64 * 16],
type: ['utf', 'asc', 'buf'],
dur: [5],
}, {
test: { len: 1024 },
});
let chunk;
let encoding;
function main({ dur, len, type }) {
switch (type) {
case 'buf':
chunk = Buffer.alloc(len, 'x');
break;
case 'utf':
encoding = 'utf8';
chunk = 'ü'.repeat(len / 2);
break;
case 'asc':
encoding = 'ascii';
chunk = 'x'.repeat(len);
break;
default:
throw new Error(`invalid type: ${type}`);
}
const reader = new Reader();
const writer = new Writer();
// The actual benchmark.
const server = net.createServer((socket) => {
socket.pipe(writer);
});
server.listen(PORT, () => {
const socket = net.connect(PORT);
socket.on('connect', () => {
bench.start();
reader.pipe(socket);
setTimeout(() => {
const bytes = writer.received;
const gbits = (bytes * 8) / (1024 * 1024 * 1024);
bench.end(gbits);
process.exit(0);
}, dur * 1000);
});
});
}
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 flow() {
const dest = this.dest;
const res = dest.write(chunk, encoding);
if (!res)
dest.once('drain', this.flow);
else
process.nextTick(this.flow);
}
function Reader() {
this.flow = flow.bind(this);
this.readable = true;
}
Reader.prototype.pipe = function(dest) {
this.dest = dest;
this.flow();
return dest;
};

View File

@ -0,0 +1,25 @@
'use strict';
const common = require('../common.js');
const { isIPv4 } = require('net');
const ips = [
'0.0.0.0',
'255.255.255.255',
'0.0.0.0.0',
'192.168.0.1',
'10.168.209.250',
];
const bench = common.createBenchmark(main, {
n: [1e7],
});
function main({ n }) {
bench.start();
for (let i = 0; i < n; ++i) {
for (let j = 0; j < ips.length; ++j)
isIPv4(ips[j]);
}
bench.end(n);
}

View File

@ -0,0 +1,23 @@
'use strict';
const common = require('../common.js');
const { isIPv6 } = require('net');
const ips = [
'::1',
'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
'0.0.0.0',
];
const bench = common.createBenchmark(main, {
n: [1e7],
});
function main({ n }) {
bench.start();
for (let i = 0; i < n; ++i) {
for (let j = 0; j < ips.length; ++j)
isIPv6(ips[j]);
}
bench.end(n);
}

105
benchmark/net/net-pipe.js Normal file
View File

@ -0,0 +1,105 @@
// Test the speed of .pipe() with sockets
'use strict';
const common = require('../common.js');
const net = require('net');
const PORT = common.PORT;
const bench = common.createBenchmark(main, {
len: [2, 64, 102400, 1024 * 64 * 16],
type: ['utf', 'asc', 'buf'],
dur: [5],
}, {
test: { len: 1024 },
});
let chunk;
let encoding;
function main({ dur, len, type }) {
switch (type) {
case 'buf':
chunk = Buffer.alloc(len, 'x');
break;
case 'utf':
encoding = 'utf8';
chunk = 'ü'.repeat(len / 2);
break;
case 'asc':
encoding = 'ascii';
chunk = 'x'.repeat(len);
break;
default:
throw new Error(`invalid type: ${type}`);
}
const reader = new Reader();
const writer = new Writer();
// The actual benchmark.
const server = net.createServer((socket) => {
socket.pipe(socket);
});
server.listen(PORT, () => {
const socket = net.connect(PORT);
socket.on('connect', () => {
bench.start();
reader.pipe(socket);
socket.pipe(writer);
setTimeout(() => {
// Multiply by 2 since we're sending it first one way
// 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;
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 flow() {
const dest = this.dest;
const res = dest.write(chunk, encoding);
if (!res)
dest.once('drain', this.flow);
else
process.nextTick(this.flow);
}
function Reader() {
this.flow = flow.bind(this);
this.readable = true;
}
Reader.prototype.pipe = function(dest) {
this.dest = dest;
this.flow();
return dest;
};

138
benchmark/net/net-s2c.js Normal file
View File

@ -0,0 +1,138 @@
// Test the speed of .pipe() with sockets
'use strict';
const common = require('../common.js');
const PORT = common.PORT;
const bench = common.createBenchmark(main, {
sendchunklen: [256, 32 * 1024, 128 * 1024, 16 * 64 * 1024],
type: ['utf', 'asc', 'buf'],
recvbuflen: [0, 64 * 1024, 1024 * 1024],
recvbufgenfn: ['true', 'false'],
dur: [5],
}, {
test: { sendchunklen: 256 },
});
let chunk;
let encoding;
let recvbuf;
let received = 0;
function main({ dur, sendchunklen, type, recvbuflen, recvbufgenfn }) {
if (isFinite(recvbuflen) && recvbuflen > 0)
recvbuf = Buffer.alloc(recvbuflen);
switch (type) {
case 'buf':
chunk = Buffer.alloc(sendchunklen, 'x');
break;
case 'utf':
encoding = 'utf8';
chunk = 'ü'.repeat(sendchunklen / 2);
break;
case 'asc':
encoding = 'ascii';
chunk = 'x'.repeat(sendchunklen);
break;
default:
throw new Error(`invalid type: ${type}`);
}
const reader = new Reader();
let writer;
let 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) => {
reader.pipe(socket);
});
server.listen(PORT, () => {
const socket = net.connect(socketOpts);
socket.on('connect', () => {
bench.start();
if (recvbuf === undefined)
socket.pipe(writer);
setTimeout(() => {
const bytes = received;
const gbits = (bytes * 8) / (1024 * 1024 * 1024);
bench.end(gbits);
process.exit(0);
}, dur * 1000);
});
});
}
const net = require('net');
function Writer() {
this.writable = true;
}
Writer.prototype.write = function(chunk, encoding, cb) {
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 flow() {
const dest = this.dest;
const res = dest.write(chunk, encoding);
if (!res)
dest.once('drain', this.flow);
else
process.nextTick(this.flow);
}
function Reader() {
this.flow = flow.bind(this);
this.readable = true;
}
Reader.prototype.pipe = function(dest) {
this.dest = dest;
this.flow();
return dest;
};

View File

@ -0,0 +1,97 @@
// Test the speed of .pipe() with JSStream wrapping for PassThrough streams
'use strict';
const common = require('../common.js');
const { PassThrough } = require('stream');
const bench = common.createBenchmark(main, {
len: [64, 102400, 1024 * 64 * 16],
type: ['utf', 'asc', 'buf'],
dur: [5],
}, {
test: { len: 64 },
flags: ['--expose-internals'],
});
let chunk;
let encoding;
function main({ dur, len, type }) {
// Can only require internals inside main().
const JSStreamWrap = require('internal/js_stream_socket');
switch (type) {
case 'buf':
chunk = Buffer.alloc(len, 'x');
break;
case 'utf':
encoding = 'utf8';
chunk = 'ü'.repeat(len / 2);
break;
case 'asc':
encoding = 'ascii';
chunk = 'x'.repeat(len);
break;
default:
throw new Error(`invalid type: ${type}`);
}
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(() => {
const bytes = writer.received;
const gbits = (bytes * 8) / (1024 * 1024 * 1024);
bench.end(gbits);
process.exit(0);
}, dur * 1000);
}
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 flow() {
const dest = this.dest;
const res = dest.write(chunk, encoding);
if (!res)
dest.once('drain', this.flow);
else
process.nextTick(this.flow);
}
function Reader() {
this.flow = flow.bind(this);
this.readable = true;
}
Reader.prototype.pipe = function(dest) {
this.dest = dest;
this.flow();
return dest;
};

View File

@ -0,0 +1,133 @@
// In this benchmark, we connect a client to the server, and write
// as many bytes as we can in the specified time (default = 10s)
'use strict';
const common = require('../common.js');
const util = require('util');
// If there are --dur=N and --len=N args, then
// run the function with those settings.
// if not, then queue up a bunch of child processes.
const bench = common.createBenchmark(main, {
len: [102400, 1024 * 64 * 16],
type: ['utf', 'asc', 'buf'],
dur: [5],
}, {
test: { len: 1024 },
flags: [ '--expose-internals', '--no-warnings' ],
});
function main({ dur, len, type }) {
const {
TCP,
TCPConnectWrap,
constants: TCPConstants,
} = common.binding('tcp_wrap');
const { WriteWrap } = common.binding('stream_wrap');
const PORT = common.PORT;
const serverHandle = new TCP(TCPConstants.SERVER);
let err = serverHandle.bind('127.0.0.1', PORT);
if (err)
fail(err, 'bind');
err = serverHandle.listen(511);
if (err)
fail(err, 'listen');
serverHandle.onconnection = function(err, clientHandle) {
if (err)
fail(err, 'connect');
// The meat of the benchmark is right here:
bench.start();
let bytes = 0;
setTimeout(() => {
// report in Gb/sec
bench.end((bytes * 8) / (1024 * 1024 * 1024));
process.exit(0);
}, dur * 1000);
clientHandle.onread = function(buffer) {
// We're not expecting to ever get an EOF from the client.
// Just lots of data forever.
if (!buffer)
fail('read');
// Don't slice the buffer. The point of this is to isolate, not
// simulate real traffic.
bytes += buffer.byteLength;
};
clientHandle.readStart();
};
client(type, len);
function fail(err, syscall) {
throw util._errnoException(err, syscall);
}
function client(type, len) {
let 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}`);
}
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;
let 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();
}
}
}

View File

@ -0,0 +1,146 @@
// In this benchmark, we connect a client to the server, and write
// as many bytes as we can in the specified time (default = 10s)
'use strict';
const common = require('../common.js');
const util = require('util');
// If there are --dur=N and --len=N args, then
// run the function with those settings.
// if not, then queue up a bunch of child processes.
const bench = common.createBenchmark(main, {
len: [102400, 1024 * 64 * 16],
type: ['utf', 'asc', 'buf'],
dur: [5],
}, {
test: { len: 1024 },
flags: [ '--expose-internals', '--no-warnings' ],
});
function main({ dur, len, type }) {
const {
TCP,
TCPConnectWrap,
constants: TCPConstants,
} = common.binding('tcp_wrap');
const { WriteWrap } = common.binding('stream_wrap');
const PORT = common.PORT;
function fail(err, syscall) {
throw util._errnoException(err, syscall);
}
// Server
const serverHandle = new TCP(TCPConstants.SERVER);
let err = serverHandle.bind('127.0.0.1', PORT);
if (err)
fail(err, 'bind');
err = serverHandle.listen(511);
if (err)
fail(err, 'listen');
serverHandle.onconnection = function(err, clientHandle) {
if (err)
fail(err, 'connect');
clientHandle.onread = function(buffer) {
// We're not expecting to ever get an EOF from the client.
// Just lots of data forever.
if (!buffer)
fail('read');
const writeReq = new WriteWrap();
writeReq.async = false;
err = clientHandle.writeBuffer(writeReq, Buffer.from(buffer));
if (err)
fail(err, 'write');
writeReq.oncomplete = function(status, handle, err) {
if (err)
fail(err, 'write');
};
};
clientHandle.readStart();
};
// Client
let 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}`);
}
const clientHandle = new TCP(TCPConstants.SOCKET);
const connectReq = new TCPConnectWrap();
let bytes = 0;
err = clientHandle.connect(connectReq, '127.0.0.1', PORT);
if (err)
fail(err, 'connect');
clientHandle.onread = function(buffer) {
if (!buffer)
fail('read');
bytes += buffer.byteLength;
};
connectReq.oncomplete = function(err) {
if (err)
fail(err, 'connect');
bench.start();
clientHandle.readStart();
setTimeout(() => {
// Multiply by 2 since we're sending it first one way
// then back again.
bench.end(2 * (bytes * 8) / (1024 * 1024 * 1024));
process.exit(0);
}, dur * 1000);
while (clientHandle.writeQueueSize === 0)
write();
};
function write() {
const writeReq = new WriteWrap();
writeReq.oncomplete = afterWrite;
let 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();
}
}

View File

@ -0,0 +1,136 @@
// In this benchmark, we connect a client to the server, and write
// as many bytes as we can in the specified time (default = 10s)
'use strict';
const common = require('../common.js');
const util = require('util');
// If there are dur=N and len=N args, then
// run the function with those settings.
// If not, then queue up a bunch of child processes.
const bench = common.createBenchmark(main, {
len: [102400, 1024 * 64 * 16],
type: ['utf', 'asc', 'buf'],
dur: [5],
}, {
test: { len: 1024 },
flags: [ '--expose-internals', '--no-warnings' ],
});
function main({ dur, len, type }) {
const {
TCP,
TCPConnectWrap,
constants: TCPConstants,
} = common.binding('tcp_wrap');
const { WriteWrap } = common.binding('stream_wrap');
const PORT = common.PORT;
const serverHandle = new TCP(TCPConstants.SERVER);
let err = serverHandle.bind('127.0.0.1', PORT);
if (err)
fail(err, 'bind');
err = serverHandle.listen(511);
if (err)
fail(err, 'listen');
serverHandle.onconnection = function(err, clientHandle) {
if (err)
fail(err, 'connect');
let 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}`);
}
clientHandle.readStart();
while (clientHandle.writeQueueSize === 0)
write();
function write() {
const writeReq = new WriteWrap();
writeReq.async = false;
writeReq.oncomplete = afterWrite;
let 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');
} else if (!writeReq.async) {
process.nextTick(() => {
afterWrite(0, clientHandle);
});
}
}
function afterWrite(status, handle) {
if (status)
fail(status, 'write');
while (clientHandle.writeQueueSize === 0)
write();
}
};
client(dur);
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() {
let bytes = 0;
clientHandle.onread = function(buffer) {
// We're not expecting to ever get an EOF from the client.
// Just lots of data forever.
if (!buffer)
fail('read');
// Don't slice the buffer. The point of this is to isolate, not
// simulate real traffic.
bytes += buffer.byteLength;
};
clientHandle.readStart();
// The meat of the benchmark is right here:
bench.start();
setTimeout(() => {
// report in Gb/sec
bench.end((bytes * 8) / (1024 * 1024 * 1024));
process.exit(0);
}, dur * 1000);
};
}
}