mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
benchmark: add zstdCompress benchmark
Signed-off-by: James Ross <james@jross.me> PR-URL: https://github.com/nodejs/node/pull/66358 Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
This commit is contained in:
1 parent
9b350d80ff
commit
168b764fec
1 file changed
+41
@@ -0,0 +1,41 @@
|
||||
'use strict';
|
||||
const common = require('../common.js');
|
||||
const fs = require('fs');
|
||||
const zlib = require('zlib');
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
method: ['zstdCompress', 'zstdCompressSync'],
|
||||
level: [3, 12],
|
||||
inputLen: [16 * 1024, 256 * 1024],
|
||||
n: [100],
|
||||
});
|
||||
|
||||
function main({ n, method, level, inputLen }) {
|
||||
const input = Buffer.alloc(inputLen, fs.readFileSync(__filename));
|
||||
const opts = { params: { [zlib.constants.ZSTD_c_compressionLevel]: level } };
|
||||
|
||||
switch (method) {
|
||||
// Performs `n` single zstdCompress operations
|
||||
case 'zstdCompress': {
|
||||
let i = 0;
|
||||
bench.start();
|
||||
(function next(err) {
|
||||
if (err) throw err;
|
||||
if (i++ === n)
|
||||
return bench.end(n);
|
||||
zlib.zstdCompress(input, opts, next);
|
||||
})();
|
||||
break;
|
||||
}
|
||||
// Performs `n` single zstdCompressSync operations
|
||||
case 'zstdCompressSync': {
|
||||
bench.start();
|
||||
for (let i = 0; i < n; ++i)
|
||||
zlib.zstdCompressSync(input, opts);
|
||||
bench.end(n);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new Error('Unsupported zstd method');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user