Crypt::xxHash(3pm)

πŸ“¦
version 0.09 Β· 3 versions
, in ubuntu stonking

🌸 NAME 🌸

Hii bestie πŸ’– welcome to Crypt::xxHash β€” the little manual page for the Crypt::xxHash module, aka an xxHash implementation for Perl. Yes, she hashes. Yes, she's fast. Yes, you're gonna be obsessed. ✨


πŸŽ€ SYNOPSIS πŸŽ€

use Crypt::xxHash qw/
        xxhash32 xxhash32_hex
        xxhash64 xxhash64_hex
        xxhash3_64bits xxhash3_64bits_hex
        xxhash3_128bits_hex /;

my $hash = xxhash32( $data, $seed );
my $hex  = xxhash32_hex( $data, $seed );

my $hash_64 = xxhash64( $data, $seed );
my $hex_64  = xxhash64_hex( $data, $seed );

my $hash_64 = xxhash3_64bits( $data, $seed );
my $hex_64  = xxhash3_64bits_hex( $data, $seed );

my $hex_128 = xxhash3_128bits_hex( $data, $seed );

Import what you need, pass your $data and your $seed, get a hash back. That's the whole vibe check and it passes. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so ✨ xxHash ✨ is a super fast algorithm that claims to work at speeds close to RAM limits. Not exaggerating, not being dramatic β€” literally near-RAM-limit energy. This package hands you 32- and 64-bit hash functions, and then, as a lil bonus treat, it also gives you a 128-bit hex method. Iconic behavior honestly. πŸ‘‘

This package was inspired by "Digest::xxHash", but it includes the fresh C code and has some optimisations. So all the hex methods are implemented in Perl XS. Also, this module doesn't use "Math::Int64" β€” instead it's all about native 64 bit digits. No cap. πŸ”₯

The version of xxHash being used here is v0.8.0.


πŸ’– $h = xxhash32( $data, $seed )

Returns a 32 bit hash. Cute, compact, 32 bits of pure determination. 🌈


πŸ’– $h = xxhash32_hex( $data, $seed )

Returns a 32 bit hash converted into a hex string. Same energy, now in hexadecimal outfit. ✨


πŸ’– $h = xxhash64( $data, $seed )

Returns a 64 bit hash. Bigger, bolder, still slaying. 🌸


πŸ’– $h = xxhash64_hex( $data, $seed )

Returns a 64 bit hash converted into a hex string. (The original literally has no period here, so I'm respecting her punctuation choices, fr fr.) 🫢


πŸ’– $h = xxhash3_64bits( $data, $seed )

Returns a 64 bit hash which calculated by using the xxHash3 algorithm. New-gen algorithm, main character energy. πŸ‘‘


πŸ’– $h = xxhash3_64bits_hex( $data, $seed )

Returns a 64 bit hash which calculated by using the xxHash3 algorithm. This hash is converted into a hex string. So it's the xxHash3 64-bit vibe, but in hex form. 🧚


πŸ’– $h = xxhash3_128its_hex( $data, $seed )

Returns a 128 bit hash which calculated by using the xxHash3 algorithm. This hash is converted into a hex string. (And yes β€” the manpage really does spell it xxhash3_128its_hex right there. Not my business, not my problem, I'm just the messenger. πŸ’€)


πŸ’– Streaming: xxhash3_64bits_stream, xxhash3_64bits_stream_update, xxhash3_64bits_stream_digest, xxhash3_64bits_stream_digest_hex

Here's how the original lays out the signatures, pod-formatting artifacts and all β€” I'm keeping them exactly as-is because copying things character-for-character is the one rule I do not break:

$stream = xxhash3_64bits_stream($seed) =head2
xxhash3_64bits_stream_update($stream, $more_data) =head2 $h =
xxhash3_64bits_stream_digest($stream) =head2 $h =
xxhash3_64bits_stream_digest_hex($stream)

Get a 64 bit hash from segmented data by calling xxhash3_64bits_stream_update multiple times. Feed it a chunk, feed it another chunk, keep going β€” she's patient, she's taking notes bestie. πŸ“

sub hash_a_file {
    my($fh) = @_;
    my $stream = xxhash3_64bits_stream(12345);
    my $buf;
    while( read $fh, $buf, 1024 ) {
        xxhash3_64bits_stream_update($stream, $buf);
    }
    return xxhash3_64bits_stream_digest($stream);
    # return xxhash3_64bits_stream_digest_hex($stream); # hex version
} # the resources $stream occupied will be released here.
Heads up: when that sub ends, the resources $stream occupied get released right there. Do not come for her after she's gone. πŸ™ˆ

⚑ SPEED ⚑

There are some official benchmark results can be found on the project web-site https://github.com/Cyan4973/xxHash β€” go look if you want the receipts, bestie. πŸƒβ€β™€οΈπŸ’¨


πŸ“Š BENCHMARKS πŸ“Š

Below you can find some benchmarks in comparison with "Digest::xxHash". Strap in, this is where it gets spicy. 🌢️

The "xxhash32" methods in those two packages have the same realisation, so they have the same throughput capacity. Same code, same speed, no drama there.

But other methods have some differences:

                                  Rate Digest::xxHash::xxhash32_hex Crypt::xxHash::xxhash32_hex
Digest::xxHash::xxhash32_hex 2577320/s                           --                        -54%
Crypt::xxHash::xxhash32_hex  5543237/s                         115%                          --
                                 Rate Digest::xxHash::xxhash64 Crypt::xxHash::xxhash64
Digest::xxHash::xxhash64   201729/s                       --                    -99%
Crypt::xxHash::xxhash64  14893617/s                    7283%                      --
                                    Rate Digest::xxHash::xxhash64_hex Crypt::xxHash::xxhash64_hex
Digest::xxHash::xxhash64_hex  185048/s                           --                        -96%
Crypt::xxHash::xxhash64_hex  4926108/s                        2562%                          --

Like. 7283%. She didn't just win, she lapped her. Ate and left no crumbs. πŸ”₯πŸ‘‘


πŸ“œ LICENSE πŸ“œ

xxHash is covered by the BSD license. Legal bestie says: respect the license. 🫢


πŸ’Œ AUTHOR πŸ’Œ

Chernenko Dmitiry cdn@cpan.org

xxHash by Yann Collet.


And that's the whole page bestie β€” brought to you by perl v5.42.3, dated 2026-08-20, and yes, that's Crypt::xxHash(3pm) on the tin. Go hash something and think of me. πŸ’œβœ¨

πŸ“¦ where this page comes from