-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add benchmarks comparing checksum algorithms (#1)
- Loading branch information
Showing
5 changed files
with
288 additions
and
1 deletion.
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 @@ | ||
nodeLinker: node-modules |
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 |
---|---|---|
@@ -1 +1,42 @@ | ||
# benchmark-checksums | ||
# benchmark-checksums | ||
|
||
Benchmarks checksum implementations used by AWS SDK for JavaScript. | ||
|
||
## Pre-requisites | ||
|
||
- Install [Node.js](https://nodejs.org/) | ||
- Run `corepack enable`. | ||
|
||
## Results | ||
|
||
```console | ||
$ yarn bench | ||
|
||
Benchmark for buffer of size 16 KB: | ||
crc32 x 5,847 ops/sec ±0.94% (97 runs sampled) | ||
crc32c x 5,696 ops/sec ±2.56% (95 runs sampled) | ||
sha1 x 115,813 ops/sec ±3.62% (89 runs sampled) | ||
sha256 x 117,583 ops/sec ±2.80% (87 runs sampled) | ||
Fastest is sha256,sha1 | ||
|
||
Benchmark for buffer of size 64 KB: | ||
crc32 x 1,438 ops/sec ±0.58% (97 runs sampled) | ||
crc32c x 1,378 ops/sec ±4.90% (93 runs sampled) | ||
sha1 x 33,010 ops/sec ±2.74% (91 runs sampled) | ||
sha256 x 34,076 ops/sec ±1.57% (91 runs sampled) | ||
Fastest is sha256 | ||
|
||
Benchmark for buffer of size 256 KB: | ||
crc32 x 361 ops/sec ±1.13% (93 runs sampled) | ||
crc32c x 367 ops/sec ±0.43% (94 runs sampled) | ||
sha1 x 9,096 ops/sec ±0.43% (101 runs sampled) | ||
sha256 x 9,178 ops/sec ±0.58% (100 runs sampled) | ||
Fastest is sha256 | ||
|
||
Benchmark for buffer of size 1024 KB: | ||
crc32 x 90.94 ops/sec ±0.36% (79 runs sampled) | ||
crc32c x 90.49 ops/sec ±0.47% (79 runs sampled) | ||
sha1 x 2,261 ops/sec ±1.45% (96 runs sampled) | ||
sha256 x 2,111 ops/sec ±7.35% (91 runs sampled) | ||
Fastest is sha1 | ||
``` |
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 @@ | ||
{ | ||
"name": "benchmark-checksums", | ||
"version": "1.0.0", | ||
"description": "Benchmarks checksum implementations used by AWS SDK for JavaScript.", | ||
"main": "index.js", | ||
"type": "module", | ||
"scripts": { | ||
"bench": "node src/bench.js" | ||
}, | ||
"keywords": [ | ||
"benchmark", | ||
"checksum", | ||
"aws-sdk-js" | ||
], | ||
"author": "Kamat, Trivikram <[email protected]>", | ||
"license": "MIT", | ||
"packageManager": "[email protected]", | ||
"dependencies": { | ||
"@aws-crypto/crc32": "^5.2.0", | ||
"@aws-crypto/crc32c": "^5.2.0", | ||
"@smithy/hash-node": "^3.0.6", | ||
"benchmark": "^2.1.4" | ||
} | ||
} |
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,51 @@ | ||
import benchmark from "benchmark"; | ||
import { AwsCrc32 } from "@aws-crypto/crc32"; | ||
import { AwsCrc32c } from "@aws-crypto/crc32c"; | ||
import { Hash } from "@smithy/hash-node"; | ||
|
||
const generateBuffer = (size) => { | ||
const buf = Buffer.alloc(size); | ||
for (let i = 0; i < size; i++) buf[i] = parseInt(Math.random() * 256); | ||
return buf; | ||
}; | ||
|
||
const crc32 = new AwsCrc32(); | ||
const crc32c = new AwsCrc32c(); | ||
const sha1 = new (Hash.bind(null, "sha1"))(); | ||
const sha256 = new (Hash.bind(null, "sha256"))(); | ||
|
||
for (const bufferSizeInKB of [16, 64, 256, 1024]) { | ||
const suite = new benchmark.Suite(); | ||
const testBuffer = generateBuffer(bufferSizeInKB * 1024); | ||
|
||
console.log(`\nBenchmark for buffer of size ${bufferSizeInKB} KB:`); | ||
suite | ||
.add("crc32", () => { | ||
crc32.update(testBuffer); | ||
crc32.digest(16); | ||
crc32.reset(); | ||
}) | ||
.add("crc32c", () => { | ||
crc32c.update(testBuffer); | ||
crc32c.digest(16); | ||
crc32c.reset(); | ||
}) | ||
.add("sha1", () => { | ||
sha1.update(testBuffer); | ||
sha1.digest(16); | ||
sha1.reset(); | ||
}) | ||
.add("sha256", () => { | ||
sha256.update(testBuffer); | ||
sha256.digest(16); | ||
sha256.reset(); | ||
}) | ||
.on("cycle", (event) => { | ||
console.log(String(event.target)); | ||
}) | ||
.on("complete", () => { | ||
console.log("Fastest is " + suite.filter("fastest").map("name")); | ||
}) | ||
// run sync | ||
.run({ async: false }); | ||
} |
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,170 @@ | ||
# This file is generated by running "yarn install" inside your project. | ||
# Manual changes might be lost - proceed with caution! | ||
|
||
__metadata: | ||
version: 8 | ||
cacheKey: 10c0 | ||
|
||
"@aws-crypto/crc32@npm:^5.2.0": | ||
version: 5.2.0 | ||
resolution: "@aws-crypto/crc32@npm:5.2.0" | ||
dependencies: | ||
"@aws-crypto/util": "npm:^5.2.0" | ||
"@aws-sdk/types": "npm:^3.222.0" | ||
tslib: "npm:^2.6.2" | ||
checksum: 10c0/eab9581d3363af5ea498ae0e72de792f54d8890360e14a9d8261b7b5c55ebe080279fb2556e07994d785341cdaa99ab0b1ccf137832b53b5904cd6928f2b094b | ||
languageName: node | ||
linkType: hard | ||
|
||
"@aws-crypto/crc32c@npm:^5.2.0": | ||
version: 5.2.0 | ||
resolution: "@aws-crypto/crc32c@npm:5.2.0" | ||
dependencies: | ||
"@aws-crypto/util": "npm:^5.2.0" | ||
"@aws-sdk/types": "npm:^3.222.0" | ||
tslib: "npm:^2.6.2" | ||
checksum: 10c0/223efac396cdebaf5645568fa9a38cd0c322c960ae1f4276bedfe2e1031d0112e49d7d39225d386354680ecefae29f39af469a84b2ddfa77cb6692036188af77 | ||
languageName: node | ||
linkType: hard | ||
|
||
"@aws-crypto/util@npm:^5.2.0": | ||
version: 5.2.0 | ||
resolution: "@aws-crypto/util@npm:5.2.0" | ||
dependencies: | ||
"@aws-sdk/types": "npm:^3.222.0" | ||
"@smithy/util-utf8": "npm:^2.0.0" | ||
tslib: "npm:^2.6.2" | ||
checksum: 10c0/0362d4c197b1fd64b423966945130207d1fe23e1bb2878a18e361f7743c8d339dad3f8729895a29aa34fff6a86c65f281cf5167c4bf253f21627ae80b6dd2951 | ||
languageName: node | ||
linkType: hard | ||
|
||
"@aws-sdk/types@npm:^3.222.0": | ||
version: 3.654.0 | ||
resolution: "@aws-sdk/types@npm:3.654.0" | ||
dependencies: | ||
"@smithy/types": "npm:^3.4.2" | ||
tslib: "npm:^2.6.2" | ||
checksum: 10c0/24c31b3685ada211a5a6ab35c95fdc6120189a8766fc02dafcf749febb895ee806a055c04c4a023146dc587bce3cf1053a23029285d6d3b3e8c197937d6a7843 | ||
languageName: node | ||
linkType: hard | ||
|
||
"@smithy/hash-node@npm:^3.0.6": | ||
version: 3.0.6 | ||
resolution: "@smithy/hash-node@npm:3.0.6" | ||
dependencies: | ||
"@smithy/types": "npm:^3.4.2" | ||
"@smithy/util-buffer-from": "npm:^3.0.0" | ||
"@smithy/util-utf8": "npm:^3.0.0" | ||
tslib: "npm:^2.6.2" | ||
checksum: 10c0/c79d1013ccfc14edb5ca7e7465abc75b71b0a4db2ebab8b87c5689f63a9ed2d15e43241985a2797805c083aa11ceee05c8c75eacd0aea0c13276ccbeb08dfc67 | ||
languageName: node | ||
linkType: hard | ||
|
||
"@smithy/is-array-buffer@npm:^2.2.0": | ||
version: 2.2.0 | ||
resolution: "@smithy/is-array-buffer@npm:2.2.0" | ||
dependencies: | ||
tslib: "npm:^2.6.2" | ||
checksum: 10c0/2f2523cd8cc4538131e408eb31664983fecb0c8724956788b015aaf3ab85a0c976b50f4f09b176f1ed7bbe79f3edf80743be7a80a11f22cd9ce1285d77161aaf | ||
languageName: node | ||
linkType: hard | ||
|
||
"@smithy/is-array-buffer@npm:^3.0.0": | ||
version: 3.0.0 | ||
resolution: "@smithy/is-array-buffer@npm:3.0.0" | ||
dependencies: | ||
tslib: "npm:^2.6.2" | ||
checksum: 10c0/44710d94b9e6655ebc02169c149ea2bc5d5b9e509b6b39511cfe61bac571412290f4b9c743d61e395822f014021fcb709dbb533f2f717c1ac2d5a356696c22fd | ||
languageName: node | ||
linkType: hard | ||
|
||
"@smithy/types@npm:^3.4.2": | ||
version: 3.4.2 | ||
resolution: "@smithy/types@npm:3.4.2" | ||
dependencies: | ||
tslib: "npm:^2.6.2" | ||
checksum: 10c0/b3a583c3c9116952008b0227be1b1513447ed08e8f65c7b82c0c8299b2520b6e0544de0225d6baf3afe65db4fe5a37c4ed5622bac3d516058bc4a3d4bbad0ec6 | ||
languageName: node | ||
linkType: hard | ||
|
||
"@smithy/util-buffer-from@npm:^2.2.0": | ||
version: 2.2.0 | ||
resolution: "@smithy/util-buffer-from@npm:2.2.0" | ||
dependencies: | ||
"@smithy/is-array-buffer": "npm:^2.2.0" | ||
tslib: "npm:^2.6.2" | ||
checksum: 10c0/223d6a508b52ff236eea01cddc062b7652d859dd01d457a4e50365af3de1e24a05f756e19433f6ccf1538544076b4215469e21a4ea83dc1d58d829725b0dbc5a | ||
languageName: node | ||
linkType: hard | ||
|
||
"@smithy/util-buffer-from@npm:^3.0.0": | ||
version: 3.0.0 | ||
resolution: "@smithy/util-buffer-from@npm:3.0.0" | ||
dependencies: | ||
"@smithy/is-array-buffer": "npm:^3.0.0" | ||
tslib: "npm:^2.6.2" | ||
checksum: 10c0/b10fb81ef34f95418f27c9123c2c1774e690dd447e8064184688c553156bdec46d2ba1b1ae3bad7edd2b58a5ef32ac569e1ad814b36e7ee05eba10526d329983 | ||
languageName: node | ||
linkType: hard | ||
|
||
"@smithy/util-utf8@npm:^2.0.0": | ||
version: 2.3.0 | ||
resolution: "@smithy/util-utf8@npm:2.3.0" | ||
dependencies: | ||
"@smithy/util-buffer-from": "npm:^2.2.0" | ||
tslib: "npm:^2.6.2" | ||
checksum: 10c0/e18840c58cc507ca57fdd624302aefd13337ee982754c9aa688463ffcae598c08461e8620e9852a424d662ffa948fc64919e852508028d09e89ced459bd506ab | ||
languageName: node | ||
linkType: hard | ||
|
||
"@smithy/util-utf8@npm:^3.0.0": | ||
version: 3.0.0 | ||
resolution: "@smithy/util-utf8@npm:3.0.0" | ||
dependencies: | ||
"@smithy/util-buffer-from": "npm:^3.0.0" | ||
tslib: "npm:^2.6.2" | ||
checksum: 10c0/b568ed84b4770d2ae9b632eb85603765195a791f045af7f47df1369dc26b001056f4edf488b42ca1cd6d852d0155ad306a0d6531e912cb4e633c0d87abaa8899 | ||
languageName: node | ||
linkType: hard | ||
|
||
"benchmark-checksums@workspace:.": | ||
version: 0.0.0-use.local | ||
resolution: "benchmark-checksums@workspace:." | ||
dependencies: | ||
"@aws-crypto/crc32": "npm:^5.2.0" | ||
"@aws-crypto/crc32c": "npm:^5.2.0" | ||
"@smithy/hash-node": "npm:^3.0.6" | ||
benchmark: "npm:^2.1.4" | ||
languageName: unknown | ||
linkType: soft | ||
|
||
"benchmark@npm:^2.1.4": | ||
version: 2.1.4 | ||
resolution: "benchmark@npm:2.1.4" | ||
dependencies: | ||
lodash: "npm:^4.17.4" | ||
platform: "npm:^1.3.3" | ||
checksum: 10c0/510224c01f7578e9aa60cef67ec3dd8f84ac6670007bcc96285f87865375122aca0853ab4e542cc80cfeeed436356dfdd63bb66cb5e72365abb912685b2139be | ||
languageName: node | ||
linkType: hard | ||
|
||
"lodash@npm:^4.17.4": | ||
version: 4.17.21 | ||
resolution: "lodash@npm:4.17.21" | ||
checksum: 10c0/d8cbea072bb08655bb4c989da418994b073a608dffa608b09ac04b43a791b12aeae7cd7ad919aa4c925f33b48490b5cfe6c1f71d827956071dae2e7bb3a6b74c | ||
languageName: node | ||
linkType: hard | ||
|
||
"platform@npm:^1.3.3": | ||
version: 1.3.6 | ||
resolution: "platform@npm:1.3.6" | ||
checksum: 10c0/69f2eb692e15f1a343dd0d9347babd9ca933824c8673096be746ff66f99f2bdc909fadd8609076132e6ec768349080babb7362299f2a7f885b98f1254ae6224b | ||
languageName: node | ||
linkType: hard | ||
|
||
"tslib@npm:^2.6.2": | ||
version: 2.7.0 | ||
resolution: "tslib@npm:2.7.0" | ||
checksum: 10c0/469e1d5bf1af585742128827000711efa61010b699cb040ab1800bcd3ccdd37f63ec30642c9e07c4439c1db6e46345582614275daca3e0f4abae29b0083f04a6 | ||
languageName: node | ||
linkType: hard |