Closed elithrar closed 7 years ago
I tried it, too and farmhash seems to be the fastest thats for sure. Also using IPv6 none of the hash methods does deliver good results, except for farmhash.
IPv6
----------
benchmarking int31...
time (ms): 417
scatter: { '0': 568888, '1': 220419, '2': 94915, '3': 115778 }
benchmarking numeric_real...
time (ms): 826
scatter: { NaN: 1000000 }
benchmarking simple_regex...
time (ms): 704
scatter: { NaN: 1000000 }
benchmarking simple_loop...
time (ms): 1292
scatter: { '0': 891094, '1': 35005, '2': 38494, '3': 35407 }
benchmarking farmhash...
time (ms): 316
scatter: { '0': 250239, '1': 249119, '2': 250724, '3': 249918 }
@MickL merged your pull request, thanks!
Google's farmhash (Node.js port) is an extremely fast hash with good quality, especially given that IPs don't tend to have an even distribution (private ranges, multicast, geographical allocation biases).
Running the benchmark gives good results and is faster than even a simple loop (due to the fact that FarmHash is written in C++):
Of course, this is nitpicking, but useful if you are dealing with high levels of traffic where Node's cluster package is most useful.
Provided this is OK, I can submit a PR w/ results + some prose to explain.