npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

js-xxhash

v4.0.0

Published

Pure JS implementation of xxhash

Downloads

668,521

Readme

xxHash

Pure Javascript / Typescript Implementation of xxHash

This is an implementation for the XXH32 Algorithm A 64-bit version might come a bit later.

Why another version

  • I needed a fast simple hash for short to medium sized strings.
  • It needed to be pure JS.

Installation

npm install --save js-xxhash

Usage

Pure JS

Internally it uses TextEncoder to convert strings to a UTF-8 Uint8Arrays.

import { xxHash32 } from 'js-xxhash';

let seed = 0;
let str = 'My text to hash 😊';
let hashNum = xxHash32(str, seed);
console.log(hashNum.toString(16));

Expected:

af7fd356

Node JS

import { xxHash32 } from 'js-xxhash';

let seed = 0;
let str = 'My text to hash 😊';
let hashNum = xxHash32(str, seed);
console.log(hashNum.toString(16));

Browser

// Using a bundler
import { xxHash32 } from 'js-xxhash';
// Using a CDN like jsDelivr
import { xxHash32 } from 'https://cdn.jsdelivr.net/npm/js-xxhash@{version}/index.mjs';

let seed = 0;
let str = 'My text to hash 😊';
let hashNum = xxHash32(str, seed);
console.log(hashNum.toString(16));

Performance

To evaluate performance this package was compared to:

One average a lorem-ipsum "word" is between 5 and 6 characters.

Performance for Strings

Running Perf Suite: xxhash-string-words-10
Evaluate xxhash performance with a string of 10 words.
✔ js-xxhash string       731_148.14 ops/sec
✔ xxhashjs string        432_753.87 ops/sec
✔ xxhash-wasm string   3_381_907.91 ops/sec

Running Perf Suite: xxhash-string-words-100
Evaluate xxhash performance with a string of 100 words.
✔ js-xxhash string       420_458.19 ops/sec
✔ xxhashjs string        124_443.56 ops/sec
✔ xxhash-wasm string   2_289_457.63 ops/sec

Running Perf Suite: xxhash-string-words-1000
Evaluate xxhash performance with a string of 1000 words.
✔ js-xxhash string        74_861.33 ops/sec
✔ xxhashjs string         16_656.57 ops/sec
✔ xxhash-wasm string     729_339.20 ops/sec

Running Perf Suite: xxhash-string-words-10000
Evaluate xxhash performance with a string of 10000 words.
✔ js-xxhash string         6_293.40 ops/sec
✔ xxhashjs string            551.90 ops/sec
✔ xxhash-wasm string      90_170.30 ops/sec

Running Perf Suite: xxhash-string-words-100000
Evaluate xxhash performance with a string of 100000 words.
✔ js-xxhash string           709.30 ops/sec
✔ xxhashjs string             40.05 ops/sec
✔ xxhash-wasm string       8_093.17 ops/sec

Performance with a Uint8Array Buffer

Running Perf Suite: xxhash-buffer-words-10
Evaluate xxhash performance with a buffer containing a string of 10 words.
✔ js-xxhash buffer       2_859_850.03 ops/sec
✔ xxhashjs buffer          699_053.22 ops/sec
✔ xxhash-wasm buffer     3_657_504.67 ops/sec

Running Perf Suite: xxhash-buffer-words-100
Evaluate xxhash performance with a buffer containing a string of 100 words.
✔ js-xxhash buffer         800_609.77 ops/sec
✔ xxhashjs buffer          402_424.91 ops/sec
✔ xxhash-wasm buffer     2_569_294.66 ops/sec

Running Perf Suite: xxhash-buffer-words-1000
Evaluate xxhash performance with a buffer containing a string of 1000 words.
✔ js-xxhash buffer         79_925.04 ops/sec
✔ xxhashjs buffer          55_568.13 ops/sec
✔ xxhash-wasm buffer      753_856.33 ops/sec

Running Perf Suite: xxhash-buffer-words-10000
Evaluate xxhash performance with a buffer containing a string of 10000 words.
✔ js-xxhash buffer          8_152.57 ops/sec
✔ xxhashjs buffer           6_046.82 ops/sec
✔ xxhash-wasm buffer      104_463.50 ops/sec

Running Perf Suite: xxhash-buffer-words-100000
Evaluate xxhash performance with a buffer containing a string of 100000 words.
✔ js-xxhash buffer            458.33 ops/sec
✔ xxhashjs buffer             602.90 ops/sec
✔ xxhash-wasm buffer        9_835.61 ops/sec