-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
benchmark against node:zlib.crc32 implementation
- Loading branch information
1 parent
fc79b0d
commit 1eebdd4
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
}, | ||
|