Skip to content
Merged
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
20 changes: 12 additions & 8 deletions packages/xxhash/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,23 @@ Memory: 32688MiB
### Result

```
@node-rs/xxhash h32 x 4,663 ops/sec ±6.22% (81 runs sampled)
xxhashjs h32 x 1,880 ops/sec ±7.11% (75 runs sampled)
@node-rs/xxhash h32 x 18,847 ops/sec ±3.81% (81 runs sampled)
xxhash c++ x 12,190 ops/sec ±2.94% (83 runs sampled)
xxhashjs h32 x 1,035 ops/sec ±11.04% (68 runs sampled)
xxh32 bench suite: Fastest is @node-rs/xxhash h32

@node-rs/xxhash h32 x 13,452 ops/sec ±2.73% (80 runs sampled)
xxhashjs h32 x 2,496 ops/sec ±0.39% (97 runs sampled)
@node-rs/xxhash h32 x 13,248 ops/sec ±4.38% (78 runs sampled)
xxhashjs h32 x 1,366 ops/sec ±1.96% (85 runs sampled)
xxh32 multi steps bench suite: Fastest is @node-rs/xxhash h32

@node-rs/xxhash 64 x 15,806 ops/sec ±3.14% (79 runs sampled)
xxhashjs h64 x 69.11 ops/sec ±5.99% (60 runs sampled)
@node-rs/xxhash 64 x 43,532 ops/sec ±1.33% (88 runs sampled)
xxhash C++ x 41,658 ops/sec ±1.45% (90 runs sampled)
wasm x 32,415 ops/sec ±1.38% (90 runs sampled)
xxhashjs h64 x 47.52 ops/sec ±3.20% (62 runs sampled)
xxh64 bench suite: Fastest is @node-rs/xxhash 64

@node-rs/xxhash 64 x 13,841 ops/sec ±3.17% (82 runs sampled)
xxhashjs h64 x 79.71 ops/sec ±4.34% (70 runs sampled)
@node-rs/xxhash 64 x 33,153 ops/sec ±5.42% (76 runs sampled)
wasm x 29,477 ops/sec ±2.72% (81 runs sampled)
xxhashjs h64 x 54.96 ops/sec ±1.93% (71 runs sampled)
xxh64 multi steps bench suite: Fastest is @node-rs/xxhash 64
```
20 changes: 19 additions & 1 deletion packages/xxhash/benchmark/xxhash.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@ const { join } = require('path')

const { Suite } = require('benchmark')
const chalk = require('chalk')
const createWasmHasher = require('webpack/lib/util/hash/xxhash64')
const { hash64, hash } = require('xxhash')
const { h32: h32js, h64: h64js } = require('xxhashjs')

const { xxh32, xxh64, Xxh32, Xxh64 } = require('../index')

const FX = readFileSync(join(__dirname, '..', '..', '..', 'yarn.lock'))

const wasmHasher = createWasmHasher()

new Suite('xxh32')
.add('@node-rs/xxhash h32', () => {
xxh32(FX)
xxh32(FX, 0)
})
.add('xxhash c++', () => {
hash(FX, 0)
})
.add('xxhashjs h32', () => {
h32js(FX, 0).toNumber()
Expand Down Expand Up @@ -43,6 +50,13 @@ new Suite('xxh64')
.add('@node-rs/xxhash 64', () => {
xxh64(FX).toString(16)
})
.add('xxhash C++', () => {
hash64(FX, 0)
})
.add('wasm', () => {
wasmHasher.update(FX).digest()
wasmHasher.reset()
})
.add('xxhashjs h64', () => {
h64js(FX, 0).toString(16)
})
Expand All @@ -58,6 +72,10 @@ new Suite('xxh64 multi steps')
.add('@node-rs/xxhash 64', () => {
new Xxh64().update(FX).digest().toString(16)
})
.add('wasm', () => {
wasmHasher.update(FX).digest()
wasmHasher.reset()
})
.add('xxhashjs h64', () => {
h64js(0).update(FX).digest().toString(16)
})
Expand Down
16 changes: 8 additions & 8 deletions packages/xxhash/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,33 @@ Xxh3.prototype.reset = xxh3.reset

module.exports = {
xxh32: function xxh32(input, seed) {
return _xxh32(Buffer.from(input), seed == null ? 0 : seed)
return _xxh32(Buffer.isBuffer(input) ? input : Buffer.from(input), seed == null ? 0 : seed)
},
xxh64: function xxh64(input, seed) {
return _xxh64(Buffer.from(input), seed == null ? BigInt(0) : seed)
return _xxh64(Buffer.isBuffer(input) ? input : Buffer.from(input), seed == null ? BigInt(0) : seed)
},
Xxh32: class Xxh32 extends _Xxh32 {
update(input) {
return super.update(Buffer.from(input))
return super.update(Buffer.isBuffer(input) ? input : Buffer.from(input))
}
},
Xxh64: class Xxh64 extends _Xxh64 {
update(input) {
return super.update(Buffer.from(input))
return super.update(Buffer.isBuffer(input) ? input : Buffer.from(input))
}
},
xxh3: {
xxh64: function xxh64(input, seed) {
return xxh3.xxh64(Buffer.from(input), seed == null ? BigInt(0) : seed)
return xxh3.xxh64(Buffer.isBuffer(input) ? input : Buffer.from(input), seed == null ? BigInt(0) : seed)
},
xxh64WithSecret(input, secret) {
return xxh3.xxh64WithSecret(Buffer.from(input), Buffer.from(secret))
return xxh3.xxh64WithSecret(Buffer.isBuffer(input) ? input : Buffer.from(input), Buffer.from(secret))
},
xxh128: function xxh128(input, seed) {
return xxh3.xxh128(Buffer.from(input), seed == null ? BigInt(0) : seed)
return xxh3.xxh128(Buffer.isBuffer(input) ? input : Buffer.from(input), seed == null ? BigInt(0) : seed)
},
xxh128WithSecret(input, secret) {
return xxh3.xxh128WithSecret(Buffer.from(input), Buffer.from(secret))
return xxh3.xxh128WithSecret(Buffer.isBuffer(input) ? input : Buffer.from(input), Buffer.from(secret))
},
Xxh3,
},
Expand Down
2 changes: 2 additions & 0 deletions packages/xxhash/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
},
"devDependencies": {
"@types/xxhashjs": "^0.2.2",
"webpack": "^5.59.1",
"xxhash": "^0.3.0",
"xxhashjs": "^0.2.2"
},
"funding": {
Expand Down
55 changes: 55 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2908,6 +2908,14 @@ enhanced-resolve@^5.8.0:
graceful-fs "^4.2.4"
tapable "^2.2.0"

enhanced-resolve@^5.8.3:
version "5.8.3"
resolved "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.8.3.tgz#6d552d465cce0423f5b3d718511ea53826a7b2f0"
integrity sha512-EGAbGvH7j7Xt2nc0E7D99La1OiEs8LnyimkRgwExpUMScN6O+3x9tIWs7PLQZVNx4YD+00skHXPXi1yQHpAmZA==
dependencies:
graceful-fs "^4.2.4"
tapable "^2.2.0"

enquirer@^2.3.5, enquirer@^2.3.6:
version "2.3.6"
resolved "https://registry.npmjs.org/enquirer/-/enquirer-2.3.6.tgz#2a7fe5dd634a1e4125a975ec994ff5456dc3734d"
Expand Down Expand Up @@ -2997,6 +3005,11 @@ es-module-lexer@^0.7.1:
resolved "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-0.7.1.tgz#c2c8e0f46f2df06274cdaf0dd3f3b33e0a0b267d"
integrity sha512-MgtWFl5No+4S3TmhDmCz2ObFGm6lEpTnzbQi+Dd+pw4mlTIZTmM2iAs5gRlmx5zS9luzobCSBSI90JM/1/JgOw==

es-module-lexer@^0.9.0:
version "0.9.3"
resolved "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-0.9.3.tgz#6f13db00cc38417137daf74366f535c8eb438f19"
integrity sha512-1HQ2M2sPtxwnvOvT1ZClHyQDiggdNjURWpY2we6aMKCQiUVxTmVs2UYPLIrD84sS+kMdUwfBSylbJPwNnBrnHQ==

es-to-primitive@^1.2.1:
version "1.2.1"
resolved "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.1.tgz#e55cd4c9cdc188bcefb03b366c736323fc5c898a"
Expand Down Expand Up @@ -5022,6 +5035,11 @@ mute-stream@0.0.8, mute-stream@~0.0.4:
resolved "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d"
integrity sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==

nan@^2.13.2:
version "2.15.0"
resolved "https://registry.npmjs.org/nan/-/nan-2.15.0.tgz#3f34a473ff18e15c1b5626b62903b5ad6e665fee"
integrity sha512-8ZtvEnA2c5aYCZYd1cvgdnU6cqwixRoYg70xPLWUws5ORTa/lnw+u4amixRS/Ac5U5mQVgp9pnlSUnbNWFaWZQ==

natural-compare@^1.4.0:
version "1.4.0"
resolved "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
Expand Down Expand Up @@ -7279,6 +7297,36 @@ webpack@^5:
watchpack "^2.2.0"
webpack-sources "^3.2.0"

webpack@^5.59.1:
version "5.59.1"
resolved "https://registry.npmjs.org/webpack/-/webpack-5.59.1.tgz#60c77e9aad796252153d4d7ab6b2d4c11f0e548c"
integrity sha512-I01IQV9K96FlpXX3V0L4nvd7gb0r7thfuu1IfT2P4uOHOA77nKARAKDYGe/tScSHKnffNIyQhLC8kRXzY4KEHQ==
dependencies:
"@types/eslint-scope" "^3.7.0"
"@types/estree" "^0.0.50"
"@webassemblyjs/ast" "1.11.1"
"@webassemblyjs/wasm-edit" "1.11.1"
"@webassemblyjs/wasm-parser" "1.11.1"
acorn "^8.4.1"
acorn-import-assertions "^1.7.6"
browserslist "^4.14.5"
chrome-trace-event "^1.0.2"
enhanced-resolve "^5.8.3"
es-module-lexer "^0.9.0"
eslint-scope "5.1.1"
events "^3.2.0"
glob-to-regexp "^0.4.1"
graceful-fs "^4.2.4"
json-parse-better-errors "^1.0.2"
loader-runner "^4.2.0"
mime-types "^2.1.27"
neo-async "^2.6.2"
schema-utils "^3.1.0"
tapable "^2.1.1"
terser-webpack-plugin "^5.1.3"
watchpack "^2.2.0"
webpack-sources "^3.2.0"

well-known-symbols@^2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/well-known-symbols/-/well-known-symbols-2.0.0.tgz#e9c7c07dbd132b7b84212c8174391ec1f9871ba5"
Expand Down Expand Up @@ -7432,6 +7480,13 @@ xtend@~4.0.1:
resolved "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54"
integrity sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==

xxhash@^0.3.0:
version "0.3.0"
resolved "https://registry.npmjs.org/xxhash/-/xxhash-0.3.0.tgz#d20893a62c5b0f7260597dd55859b12a1e02c559"
integrity sha512-1ud2yyPiR1DJhgyF1ZVMt+Ijrn0VNS/wzej1Z8eSFfkNfRPp8abVZNV2u9tYy9574II0ZayZYZgJm8KJoyGLCw==
dependencies:
nan "^2.13.2"

xxhashjs@^0.2.2:
version "0.2.2"
resolved "https://registry.npmjs.org/xxhashjs/-/xxhashjs-0.2.2.tgz#8a6251567621a1c46a5ae204da0249c7f8caa9d8"
Expand Down