Commit 2758c59105a for nodejs
commit 2758c59105a4d4cffacf7ffde734379d8af1565a
Author: Trivikram Kamat <trivikr.dev@gmail.com>
Date: Sun Nov 1 09:33:40 2026 -0800
benchmark: merge crc32c into crc32 zlib benchmark
Signed-off-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com>
PR-URL: https://github.com/nodejs/node/pull/67004
Refs: https://github.com/nodejs/node/pull/66828
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
diff --git a/benchmark/zlib/crc32.js b/benchmark/zlib/crc32.js
index e70ee46afea..34b7ecfb1a9 100644
--- a/benchmark/zlib/crc32.js
+++ b/benchmark/zlib/crc32.js
@@ -1,15 +1,16 @@
'use strict';
const common = require('../common.js');
-const { crc32 } = require('zlib');
+const zlib = require('zlib');
-// Benchmark crc32 on Buffer and String inputs across sizes.
+// Benchmark crc32 and crc32c on Buffer and String inputs across sizes.
// Iteration count is scaled inversely with input length to keep runtime sane.
// Example:
-// node benchmark/zlib/crc32.js type=buffer len=4096 n=4000000
+// node benchmark/zlib/crc32.js algorithm=crc32c type=buffer len=4096 n=4000000
// ./out/Release/node benchmark/zlib/crc32.js --test
const bench = common.createBenchmark(main, {
+ algorithm: ['crc32', 'crc32c'],
type: ['buffer', 'string'],
len: [32, 256, 4096, 65536],
n: [4e6],
@@ -28,7 +29,9 @@ function makeAsciiString(size) {
return out;
}
-function main({ type, len, n }) {
+function main({ algorithm, type, len, n }) {
+ const crc = zlib[algorithm];
+
// Scale iterations so that total processed bytes roughly constant around n*4096 bytes.
const scale = 4096 / len;
const iters = Math.max(1, Math.floor(n * scale));
@@ -36,11 +39,11 @@ function main({ type, len, n }) {
const data = type === 'buffer' ? makeBuffer(len) : makeAsciiString(len);
let acc = 0;
- for (let i = 0; i < Math.min(iters, 10000); i++) acc ^= crc32(data, 0);
+ for (let i = 0; i < Math.min(iters, 10000); i++) acc ^= crc(data, 0);
bench.start();
let sum = 0;
- for (let i = 0; i < iters; i++) sum ^= crc32(data, 0);
+ for (let i = 0; i < iters; i++) sum ^= crc(data, 0);
bench.end(iters);
if (sum === acc - 1) process.stderr.write('');
diff --git a/benchmark/zlib/crc32c.js b/benchmark/zlib/crc32c.js
deleted file mode 100644
index 3a8abd0a286..00000000000
--- a/benchmark/zlib/crc32c.js
+++ /dev/null
@@ -1,47 +0,0 @@
-'use strict';
-
-const common = require('../common.js');
-const { crc32c } = require('zlib');
-
-// Benchmark crc32c on Buffer and String inputs across sizes.
-// Iteration count is scaled inversely with input length to keep runtime sane.
-// Example:
-// node benchmark/zlib/crc32c.js type=buffer len=4096 n=4000000
-// ./out/Release/node benchmark/zlib/crc32c.js --test
-
-const bench = common.createBenchmark(main, {
- type: ['buffer', 'string'],
- len: [32, 256, 4096, 65536],
- n: [4e6],
-});
-
-function makeBuffer(size) {
- const buf = Buffer.allocUnsafe(size);
- for (let i = 0; i < size; i++) buf[i] = (i * 1103515245 + 12345) & 0xff;
- return buf;
-}
-
-function makeAsciiString(size) {
- const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
- let out = '';
- for (let i = 0, j = 0; i < size; i++, j = (j + 7) % chars.length) out += chars[j];
- return out;
-}
-
-function main({ type, len, n }) {
- // Scale iterations so that total processed bytes roughly constant around n*4096 bytes.
- const scale = 4096 / len;
- const iters = Math.max(1, Math.floor(n * scale));
-
- const data = type === 'buffer' ? makeBuffer(len) : makeAsciiString(len);
-
- let acc = 0;
- for (let i = 0; i < Math.min(iters, 10000); i++) acc ^= crc32c(data, 0);
-
- bench.start();
- let sum = 0;
- for (let i = 0; i < iters; i++) sum ^= crc32c(data, 0);
- bench.end(iters);
-
- if (sum === acc - 1) process.stderr.write('');
-}