UNPKG

3.68 kBMarkdownView Raw
1# `@node-rs/xxhash`
2
3![](https://github.com/napi-rs/node-rs/workflows/CI/badge.svg)
4![](https://img.shields.io/npm/dm/@node-rs/xxhash.svg?sanitize=true)
5[![Install size](https://packagephobia.com/badge?p=@node-rs/xxhash)](https://packagephobia.com/result?p=@node-rs/xxhash)
6
7> 🚀 Help me to become a full-time open-source developer by [sponsoring me on Github](https://github.com/sponsors/Brooooooklyn)
8
9[`xxhash-rust`](https://github.com/DoumanAsh/xxhash-rust) binding for Node.js.
10
11## Install this package
12
13```
14yarn add @node-rs/xxhash
15pnpm add @node-rs/xxhash
16npm install @node-rs/xxhash
17```
18
19## Support matrix
20
21| | node12 | node14 | node16 |
22| --------------------- | ------ | ------ | ------ |
23| Windows x64 | ✓ | ✓ | ✓ |
24| Windows x32 | ✓ | ✓ | ✓ |
25| Windows arm64 | ✓ | ✓ | ✓ |
26| macOS x64 | ✓ | ✓ | ✓ |
27| macOS arm64 (m chips) | ✓ | ✓ | ✓ |
28| Linux x64 gnu | ✓ | ✓ | ✓ |
29| Linux x64 musl | ✓ | ✓ | ✓ |
30| Linux arm gnu | ✓ | ✓ | ✓ |
31| Linux arm64 gnu | ✓ | ✓ | ✓ |
32| Linux arm64 musl | ✓ | ✓ | ✓ |
33| Android arm64 | ✓ | ✓ | ✓ |
34| FreeBSD x64 | ✓ | ✓ | ✓ |
35
36## API
37
38```ts
39export type BufferLike =
40 | Buffer
41 | string
42 | Uint8Array
43 | ArrayBuffer
44 | SharedArrayBuffer
45 | ReadonlyArray<number>
46 | number[]
47
48export function xxh32(input: BufferLike, seed?: number): number
49export function xxh64(input: BufferLike, seed?: BigInt): BigInt
50
51export class Xxh32 {
52 constructor(seed?: number)
53 update(input: BufferLike): this
54 digest(): number
55 reset(): void
56}
57
58export class Xxh64 {
59 constructor(seed?: BigInt)
60 update(input: BufferLike): this
61 digest(): BigInt
62 reset(): void
63}
64
65export class Xxh3 {
66 static withSeed(seed?: BigInt): Xxh3
67 static withSecret(secret: BufferLike): Xxh3
68 private constructor() {}
69 update(input: BufferLike): this
70 digest(): BigInt
71 reset(): void
72}
73
74export const xxh3: {
75 xxh64: (input: BufferLike, seed?: BigInt) => BigInt
76 xxh64WithSecret: (input: BufferLike, secret: BufferLike) => BigInt
77 xxh128: (input: BufferLike, seed?: BigInt) => BigInt
78 xxh128WithSecret: (input: BufferLike, secret: BufferLike) => BigInt
79 Xxh3: typeof Xxh3
80}
81```
82
83## Performance
84
85### Hardware
86
87```
88Model Name: MacBook Pro
89Model Identifier: MacBookPro15,1
90Processor Name: 6-Core Intel Core i7
91Processor Speed: 2.6 GHz
92Number of Processors: 1
93Total Number of Cores: 6
94L2 Cache (per Core): 256 KB
95L3 Cache: 12 MB
96Hyper-Threading Technology: Enabled
97Memory: 16 GB
98```
99
100### Result
101
102```
103@node-rs/xxhash h32 x 18,847 ops/sec ±3.81% (81 runs sampled)
104xxhash c++ x 12,190 ops/sec ±2.94% (83 runs sampled)
105xxhashjs h32 x 1,035 ops/sec ±11.04% (68 runs sampled)
106xxh32 bench suite: Fastest is @node-rs/xxhash h32
107
108@node-rs/xxhash h32 x 13,248 ops/sec ±4.38% (78 runs sampled)
109xxhashjs h32 x 1,366 ops/sec ±1.96% (85 runs sampled)
110xxh32 multi steps bench suite: Fastest is @node-rs/xxhash h32
111
112@node-rs/xxhash 64 x 43,532 ops/sec ±1.33% (88 runs sampled)
113xxhash C++ x 41,658 ops/sec ±1.45% (90 runs sampled)
114wasm x 32,415 ops/sec ±1.38% (90 runs sampled)
115xxhashjs h64 x 47.52 ops/sec ±3.20% (62 runs sampled)
116xxh64 bench suite: Fastest is @node-rs/xxhash 64
117
118@node-rs/xxhash 64 x 33,153 ops/sec ±5.42% (76 runs sampled)
119wasm x 29,477 ops/sec ±2.72% (81 runs sampled)
120xxhashjs h64 x 54.96 ops/sec ±1.93% (71 runs sampled)
121xxh64 multi steps bench suite: Fastest is @node-rs/xxhash 64
122```