Skip to main content

hash

Function hash 

Source
pub fn hash(input: &[u8]) -> Hash
Expand description

The hash of input, on the calling thread.

let hash = blake3_servil::hash(b"foo");

let hash = blake3_servil::Hasher::new().update(b"foo").finalize();

Choose it for short inputs, or where your program wants one thread; for any input in memory, hash_multithreaded is never slower. For output sizes other than 32 bytes, see Hasher::finalize_xof and OutputReader.

Speed, nonstop on an Apple M4 Max: about 50 ns for 64 bytes, 0.7 µs for 1 KiB, 4 GB/s at 16 KiB, and 6 GB/s from 1 MiB. A call after a pause or after other work takes longer (its code and data have left the CPU’s caches): 64 bytes then take about 0.2 to 0.6 µs. On Apple M4 and later, threads that hash inputs of 16 KiB or more at the same moment share one accelerator: one runs at full speed and the others at about two thirds of it.

The first hash in a process first runs a self-test (see the crate’s documentation), under 0.2 ms; initialize moves it to start-up.