UNPKG

3.9 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 | node18 |
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| Android armv7 | ✓ | ✓ | ✓ | ✓ |
35| FreeBSD x64 | ✓ | ✓ | ✓ | ✓ |
36
37## API
38
39```ts
40export type BufferLike =
41 | Buffer
42 | string
43 | Uint8Array
44 | ArrayBuffer
45 | SharedArrayBuffer
46 | ReadonlyArray<number>
47 | number[]
48
49export function xxh32(input: BufferLike, seed?: number): number
50export function xxh64(input: BufferLike, seed?: BigInt): BigInt
51
52export class Xxh32 {
53 constructor(seed?: number)
54 update(input: BufferLike): this
55 digest(): number
56 reset(): void
57}
58
59export class Xxh64 {
60 constructor(seed?: BigInt)
61 update(input: BufferLike): this
62 digest(): BigInt
63 reset(): void
64}
65
66export class Xxh3 {
67 static withSeed(seed?: BigInt): Xxh3
68 static withSecret(secret: BufferLike): Xxh3
69 private constructor() {}
70 update(input: BufferLike): this
71 digest(): BigInt
72 reset(): void
73}
74
75export const xxh3: {
76 xxh64: (input: BufferLike, seed?: BigInt) => BigInt
77 xxh64WithSecret: (input: BufferLike, secret: BufferLike) => BigInt
78 xxh128: (input: BufferLike, seed?: BigInt) => BigInt
79 xxh128WithSecret: (input: BufferLike, secret: BufferLike) => BigInt
80 Xxh3: typeof Xxh3
81}
82```
83
84## Performance
85
86### Hardware
87
88```
89Model Name: MacBook Pro
90Model Identifier: MacBookPro15,1
91Processor Name: 6-Core Intel Core i7
92Processor Speed: 2.6 GHz
93Number of Processors: 1
94Total Number of Cores: 6
95L2 Cache (per Core): 256 KB
96L3 Cache: 12 MB
97Hyper-Threading Technology: Enabled
98Memory: 16 GB
99```
100
101### Result
102
103```
104@node-rs/xxhash h32 x 18,847 ops/sec ±3.81% (81 runs sampled)
105xxhash c++ x 12,190 ops/sec ±2.94% (83 runs sampled)
106xxhashjs h32 x 1,035 ops/sec ±11.04% (68 runs sampled)
107xxh32 bench suite: Fastest is @node-rs/xxhash h32
108
109@node-rs/xxhash h32 x 13,248 ops/sec ±4.38% (78 runs sampled)
110xxhashjs h32 x 1,366 ops/sec ±1.96% (85 runs sampled)
111xxh32 multi steps bench suite: Fastest is @node-rs/xxhash h32
112
113@node-rs/xxhash 64 x 43,532 ops/sec ±1.33% (88 runs sampled)
114xxhash C++ x 41,658 ops/sec ±1.45% (90 runs sampled)
115wasm x 32,415 ops/sec ±1.38% (90 runs sampled)
116xxhashjs h64 x 47.52 ops/sec ±3.20% (62 runs sampled)
117xxh64 bench suite: Fastest is @node-rs/xxhash 64
118
119@node-rs/xxhash 64 x 33,153 ops/sec ±5.42% (76 runs sampled)
120wasm x 29,477 ops/sec ±2.72% (81 runs sampled)
121xxhashjs h64 x 54.96 ops/sec ±1.93% (71 runs sampled)
122xxh64 multi steps bench suite: Fastest is @node-rs/xxhash 64
123```