3 ms·
I timed the Buz Hash (https://en.wikipedia.org/wiki/Rolling_hash#Cyclic_polynomial https://en.wikipedia.org/wiki/Rolling_hash#Cyclic_polynomial) at about 1.38 c
by cb321 3y ago
I timed the Buz Hash (https://en.wikipedia.org/wiki/Rolling_hash#Cyclic_polynomial https://en.wikipedia.org/wiki/Rolling_hash#Cyclic_polynomial) at about 1.38 cycles/byte on Skylake generation - but only to "hash in" (i.e. no hash-out). At 6Ghz that should translate to >4.3 GB/s/core.
There is a 25 lines of Nim code implementation over at
https://github.com/c-blake/ndup/blob/15ec9b0e67750ae1b70761ecd3362db0cf623488/framed.nim#L7 https://github.com/c-blake/ndup/blob/15ec9b0e67750ae1b70761e... but the charm of the technique / idea of Bob Uzgalis' ("buz") is its extreme simplicity. (That Nim version also uses the ease of computing very statistically independent hashes in parallel for this near duplicate detection idea.) I'm sure you could write your own pronto.
I haven't tried it, but if your CPU L1/L2 cache is big enough, you might be able to get a boost from doing 2-bytes at a time instead of 1 byte at a time. (65536 entries * hash-size per entry =~ maybe as little as 256..512 KiB. Big "IF", though.. since while you can do half as many loops, you will also be waiting a lot more on cache.
(EDIT: and dunno - it may not be as collision resistant as your end-use case needs. Perhaps that's why you qualified that sub-kind of rolling hash being of interest.)