Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add benchmark comparing performance of this package with node:zlib.crc32 #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions benchmarks/crc.bench.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const bench = require('micro-bmark');
const crc32 = require('..');
const zlib = require('node:zlib');

const smallBuffer = Buffer.from([0, 1, 2, 3, 4, 5]);
const largeBuffer = Buffer.alloc(100000);

// Do a few iterations first to get insight into the performance before JIT optimization.
bench.mark(' few iterations, small buffer, native', 10, () => zlib.crc32(smallBuffer));
bench.mark(' few iterations, small buffer, js ', 10, () => crc32.unsigned(smallBuffer));
bench.mark(' few iterations, large buffer, native', 10, () => zlib.crc32(largeBuffer));
bench.mark(' few iterations, large buffer, js ', 10, () => crc32.unsigned(largeBuffer));

// Run many iterations to warm up the JIT optimization.
bench.mark('(warm up. ignore)', 10000, () => zlib.crc32(smallBuffer));
bench.mark('(warm up. ignore)', 10000, () => crc32.unsigned(smallBuffer));
bench.mark('(warm up. ignore)', 10000, () => zlib.crc32(largeBuffer));
bench.mark('(warm up. ignore)', 10000, () => crc32.unsigned(largeBuffer));

// Then collect data once the optimization has presumably reached a steady state.
bench.mark('many iterations, small buffer, native', 20000, () => zlib.crc32(smallBuffer));
bench.mark('many iterations, small buffer, js ', 20000, () => crc32.unsigned(smallBuffer));
bench.mark('many iterations, large buffer, native', 20000, () => zlib.crc32(largeBuffer));
bench.mark('many iterations, large buffer, js ', 20000, () => crc32.unsigned(largeBuffer));
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
},
"scripts": {
"test": "tap tests/*.test.js --reporter classic",
"benchmark": "node benchmarks/crc.bench.js",
"build": "npx [email protected] && npx cpy-cli index.d.ts dist --rename=index.d.cts && npx cpy-cli index.d.ts dist --rename=index.d.mts",
"prepublishOnly": "npm run build",
"format": "prettier --write --log-level warn \"**/*.{json,md,js}\""
},
"dependencies": {},
"devDependencies": {
"micro-bmark": "^0.3.1",
"prettier": "^3.2.4",
"tap": "~11.1.5"
},
Expand Down