Skip to content

Commit cdef4ac

Browse files
trivikraduh95
authored andcommitted
benchmark: merge crc32c into crc32 zlib benchmark
Signed-off-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> PR-URL: #67004 Refs: #66828 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 6cffd6a commit cdef4ac

2 files changed

Lines changed: 9 additions & 53 deletions

File tree

‎benchmark/zlib/crc32.js‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
'use strict';
22

33
const common = require('../common.js');
4-
const { crc32 } = require('zlib');
4+
const zlib = require('zlib');
55

6-
// Benchmark crc32 on Buffer and String inputs across sizes.
6+
// Benchmark crc32 and crc32c on Buffer and String inputs across sizes.
77
// Iteration count is scaled inversely with input length to keep runtime sane.
88
// Example:
9-
// node benchmark/zlib/crc32.js type=buffer len=4096 n=4000000
9+
// node benchmark/zlib/crc32.js algorithm=crc32c type=buffer len=4096 n=4000000
1010
// ./out/Release/node benchmark/zlib/crc32.js --test
1111

1212
const bench = common.createBenchmark(main, {
13+
algorithm: ['crc32', 'crc32c'],
1314
type: ['buffer', 'string'],
1415
len: [32, 256, 4096, 65536],
1516
n: [4e6],
@@ -28,19 +29,21 @@ function makeAsciiString(size) {
2829
return out;
2930
}
3031

31-
function main({ type, len, n }) {
32+
function main({ algorithm, type, len, n }) {
33+
const crc = zlib[algorithm];
34+
3235
// Scale iterations so that total processed bytes roughly constant around n*4096 bytes.
3336
const scale = 4096 / len;
3437
const iters = Math.max(1, Math.floor(n * scale));
3538

3639
const data = type === 'buffer' ? makeBuffer(len) : makeAsciiString(len);
3740

3841
let acc = 0;
39-
for (let i = 0; i < Math.min(iters, 10000); i++) acc ^= crc32(data, 0);
42+
for (let i = 0; i < Math.min(iters, 10000); i++) acc ^= crc(data, 0);
4043

4144
bench.start();
4245
let sum = 0;
43-
for (let i = 0; i < iters; i++) sum ^= crc32(data, 0);
46+
for (let i = 0; i < iters; i++) sum ^= crc(data, 0);
4447
bench.end(iters);
4548

4649
if (sum === acc - 1) process.stderr.write('');

‎benchmark/zlib/crc32c.js‎

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)