Function img_hash::precompute_dct_matrix[][src]

pub fn precompute_dct_matrix(size: u32)

Precompute the DCT matrix for a given hash size and memoize it in thread-local storage.

If a precomputed matrix was already stored, even of the same length, it will be overwritten.

This can produce a significant runtime savings (an order of magnitude on the author's machine) when performing multiple hashing runs with the same hash size, as compared to not performing this step.

Note

This only affects the built-in DCT hash (HashType::DCT). It also includes the hash size multiplier applied by the DCT hash algorithm, so just pass the same hash size that you would to ImageHash::hash().

Note: Thread-Local

Because this uses thread-local storage, this will need to be called on every thread that will be using the DCT hash for the runtime benefit. You can also have precomputed matrices of different sizes for each thread.