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