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,32 @@
'use strict';
const common = require('../common.js');
const zlib = require('zlib');
const bench = common.createBenchmark(main, {
inputLen: [16 * 1024 * 1024],
chunkLen: [1024],
n: [1e2],
});
function main({ n, inputLen, chunkLen }) {
const input = zlib.deflateSync(Buffer.alloc(inputLen, 'a'));
let i = 0;
bench.start();
(function next() {
let p = 0;
const inflater = zlib.createInflate();
inflater.resume();
inflater.on('finish', () => {
if (i++ === n)
return bench.end(n);
next();
});
(function nextChunk() {
if (p >= input.length)
return inflater.end();
inflater.write(input.slice(p, p += chunkLen), nextChunk);
})();
})();
}

View File

@ -0,0 +1,31 @@
'use strict';
const common = require('../common.js');
const zlib = require('zlib');
const bench = common.createBenchmark(main, {
type: [
'Deflate', 'DeflateRaw', 'Inflate', 'InflateRaw', 'Gzip', 'Gunzip', 'Unzip',
'BrotliCompress', 'BrotliDecompress', 'ZstdCompress', 'ZstdDecompress',
],
options: ['true', 'false'],
n: [5e5],
});
function main({ n, type, options }) {
const fn = zlib[`create${type}`];
if (typeof fn !== 'function')
throw new Error('Invalid zlib type');
if (options === 'true') {
const opts = {};
bench.start();
for (let i = 0; i < n; ++i)
fn(opts);
bench.end(n);
} else {
bench.start();
for (let i = 0; i < n; ++i)
fn();
bench.end(n);
}
}

58
benchmark/zlib/deflate.js Normal file
View File

@ -0,0 +1,58 @@
'use strict';
const common = require('../common.js');
const zlib = require('zlib');
const bench = common.createBenchmark(main, {
method: ['createDeflate', 'deflate', 'deflateSync'],
inputLen: [1024],
n: [4e5],
});
function main({ n, method, inputLen }) {
// Default method value for testing.
method ||= 'deflate';
const chunk = Buffer.alloc(inputLen, 'a');
switch (method) {
// Performs `n` writes for a single deflate stream
case 'createDeflate': {
let i = 0;
const deflater = zlib.createDeflate();
deflater.resume();
deflater.on('finish', () => {
bench.end(n);
});
bench.start();
(function next() {
if (i++ === n)
return deflater.end();
deflater.write(chunk, next);
})();
break;
}
// Performs `n` single deflate operations
case 'deflate': {
let i = 0;
const deflate = zlib.deflate;
bench.start();
(function next(err, result) {
if (i++ === n)
return bench.end(n);
deflate(chunk, next);
})();
break;
}
// Performs `n` single deflateSync operations
case 'deflateSync': {
const deflateSync = zlib.deflateSync;
bench.start();
for (let i = 0; i < n; ++i)
deflateSync(chunk);
bench.end(n);
break;
}
default:
throw new Error('Unsupported deflate method');
}
}

41
benchmark/zlib/inflate.js Normal file
View File

@ -0,0 +1,41 @@
'use strict';
const common = require('../common.js');
const zlib = require('zlib');
const bench = common.createBenchmark(main, {
method: ['inflate', 'inflateSync'],
inputLen: [1024],
n: [4e5],
});
function main({ n, method, inputLen }) {
// Default method value for tests.
method ||= 'inflate';
const chunk = zlib.deflateSync(Buffer.alloc(inputLen, 'a'));
let i = 0;
switch (method) {
// Performs `n` single inflate operations
case 'inflate': {
const inflate = zlib.inflate;
bench.start();
(function next(err, result) {
if (i++ === n)
return bench.end(n);
inflate(chunk, next);
})();
break;
}
// Performs `n` single inflateSync operations
case 'inflateSync': {
const inflateSync = zlib.inflateSync;
bench.start();
for (; i < n; ++i)
inflateSync(chunk);
bench.end(n);
break;
}
default:
throw new Error('Unsupported inflate method');
}
}

52
benchmark/zlib/pipe.js Normal file
View File

@ -0,0 +1,52 @@
'use strict';
const common = require('../common.js');
const fs = require('fs');
const zlib = require('zlib');
const bench = common.createBenchmark(main, {
inputLen: [1024],
duration: [5],
type: ['string', 'buffer'],
algorithm: ['gzip', 'brotli', 'zstd'],
}, {
test: {
inputLen: 1024,
duration: 0.2,
},
});
const algorithms = {
'gzip': [zlib.createGzip, zlib.createGunzip],
'brotli': [zlib.createBrotliCompress, zlib.createBrotliDecompress],
'zstd': [zlib.createZstdCompress, zlib.createZstdDecompress],
};
function main({ inputLen, duration, type, algorithm }) {
const buffer = Buffer.alloc(inputLen, fs.readFileSync(__filename));
const chunk = type === 'buffer' ? buffer : buffer.toString('utf8');
const [createCompress, createUncompress] = algorithms[algorithm];
const input = createCompress();
const output = createUncompress();
let readFromOutput = 0;
input.pipe(output);
if (type === 'string')
output.setEncoding('utf8');
output.on('data', (chunk) => readFromOutput += chunk.length);
function write() {
input.write(chunk, write);
}
bench.start();
write();
setTimeout(() => {
// Give result in GBit/s, like the net benchmarks do
bench.end(readFromOutput * 8 / (1024 ** 3));
// Cut off writing the easy way.
input.write = () => {};
}, duration * 1000);
}