lovell/farmhash — pull request #2 by mranney (2014-12-16 04:17:16+00:00)
Title: Support node Buffers as well as JS Strings for 32 bit hashes

For our application, we'd like to use node Buffers, but the current implementation only supports Strings. This is a change to explore different methods of supporting Buffers and the associated performance.

Is there a better way to support Buffers?

## Performance

The Buffer methods perform significantly better than the String methods. I wasn't able to figure out exactly why. Either way, 10M ops/sec is pretty nice.

### MacBook Pro

I found that the Buffer tests ran significantly faster with the AC power connected, whereas the others weren't changed much.

Test key length performance
Using seed 865743556
Using key of length 100
murmurhash3 x 3,874,832 ops/sec ±0.53% (98 runs sampled)
murmurhash3+seed x 2,511,932 ops/sec ±0.47% (98 runs sampled)
farmhash-hash-switch-string x 2,904,867 ops/sec ±0.96% (91 runs sampled)
farmhash-hash-switch-buffer x 4,429,890 ops/sec ±0.51% (97 runs sampled)
farmhash-hash-buffer-only x 10,271,055 ops/sec ±0.59% (97 runs sampled)
farmhash-hash-string-only x 3,030,743 ops/sec ±0.94% (98 runs sampled)
farmhash-hash+seed-switch-string x 2,856,352 ops/sec ±0.84% (91 runs sampled)
farmhash-hash+seed-switch-buffer x 4,193,309 ops/sec ±0.94% (94 runs sampled)
farmhash-hash+seed-string-only x 2,948,481 ops/sec ±0.81% (96 runs sampled)
farmhash-hash+seed-buffer-only x 9,350,736 ops/sec ±0.57% (99 runs sampled)
farmhash-fingerprint x 2,179,328 ops/sec ±0.82% (99 runs sampled)
xxhash+seed x 8,007,385 ops/sec ±0.48% (97 runs sampled)
Using key of length 1000
murmurhash3 x 1,482,526 ops/sec ±0.42% (101 runs sampled)
murmurhash3+seed x 1,496,896 ops/sec ±0.39% (97 runs sampled)
farmhash-hash-switch-string x 1,663,623 ops/sec ±0.46% (101 runs sampled)
farmhash-hash-switch-buffer x 2,286,227 ops/sec ±0.40% (102 runs sampled)
farmhash-hash-buffer-only x 3,432,985 ops/sec ±0.56% (100 runs sampled)
farmhash-hash-string-only x 1,703,900 ops/sec ±0.57% (101 runs sampled)
farmhash-hash+seed-switch-string x 2,101,446 ops/sec ±0.49% (97 runs sampled)
farmhash-hash+seed-switch-buffer x 3,060,516 ops/sec ±0.42% (98 runs sampled)
farmhash-hash+seed-string-only x 2,160,667 ops/sec ±0.55% (100 runs sampled)
farmhash-hash+seed-buffer-only x 5,337,616 ops/sec ±0.49% (99 runs sampled)
farmhash-fingerprint x 1,650,335 ops/sec ±0.37% (99 runs sampled)
xxhash+seed x 3,462,425 ops/sec ±0.42% (99 runs sampled)
Using key of length 10000
murmurhash3 x 245,128 ops/sec ±0.37% (98 runs sampled)
murmurhash3+seed x 244,759 ops/sec ±0.47% (101 runs sampled)
farmhash-hash-switch-string x 513,406 ops/sec ±0.53% (98 runs sampled)
farmhash-hash-switch-buffer x 779,636 ops/sec ±0.45% (100 runs sampled)
farmhash-hash-buffer-only x 1,085,798 ops/sec ±0.56% (99 runs sampled)
farmhash-hash-string-only x 502,066 ops/sec ±0.53% (99 runs sampled)
farmhash-hash+seed-switch-string x 510,084 ops/sec ±0.51% (98 runs sampled)
farmhash-hash+seed-switch-buffer x 798,303 ops/sec ±0.43% (93 runs sampled)
farmhash-hash+seed-string-only x 506,372 ops/sec ±0.49% (96 runs sampled)
farmhash-hash+seed-buffer-only x 1,055,082 ops/sec ±0.38% (102 runs sampled)
farmhash-fingerprint x 282,423 ops/sec ±0.54% (96 runs sampled)
xxhash+seed x 618,507 ops/sec ±0.41% (100 runs sampled)

### EC2 m3.xlarge us-west-2

Test key length performance
Using seed 1993162035
Using key of length 100
murmurhash3 x 2,042,621 ops/sec ±0.40% (98 runs sampled)
murmurhash3+seed x 1,985,653 ops/sec ±0.12% (100 runs sampled)
farmhash-hash-switch-string x 2,788,833 ops/sec ±0.25% (100 runs sampled)
farmhash-hash-switch-buffer x 2,530,404 ops/sec ±0.15% (103 runs sampled)
farmhash-hash-buffer-only x 6,705,966 ops/sec ±0.83% (99 runs sampled)
farmhash-hash-string-only x 2,811,600 ops/sec ±0.04% (100 runs sampled)
farmhash-hash+seed-switch-string x 2,314,911 ops/sec ±0.12% (97 runs sampled)
farmhash-hash+seed-switch-buffer x 2,479,593 ops/sec ±0.11% (100 runs sampled)
farmhash-hash+seed-string-only x 2,711,889 ops/sec ±0.08% (97 runs sampled)
farmhash-hash+seed-buffer-only x 6,332,624 ops/sec ±0.09% (100 runs sampled)
farmhash-fingerprint x 2,765,768 ops/sec ±0.03% (103 runs sampled)
xxhash+seed x 3,594,688 ops/sec ±2.33% (92 runs sampled)
Using key of length 1000
murmurhash3 x 973,754 ops/sec ±0.58% (98 runs sampled)
murmurhash3+seed x 1,277,748 ops/sec ±1.85% (101 runs sampled)
farmhash-hash-switch-string x 1,703,791 ops/sec ±0.09% (97 runs sampled)
farmhash-hash-switch-buffer x 1,869,872 ops/sec ±0.21% (92 runs sampled)
farmhash-hash-buffer-only x 4,814,756 ops/sec ±0.24% (96 runs sampled)
farmhash-hash-string-only x 1,609,365 ops/sec ±0.09% (103 runs sampled)
farmhash-hash+seed-switch-string x 1,571,194 ops/sec ±0.06% (102 runs sampled)
farmhash-hash+seed-switch-buffer x 1,888,304 ops/sec ±0.09% (103 runs sampled)
farmhash-hash+seed-string-only x 1,649,504 ops/sec ±0.12% (102 runs sampled)
farmhash-hash+seed-buffer-only x 4,171,059 ops/sec ±0.09% (102 runs sampled)
farmhash-fingerprint x 1,050,965 ops/sec ±0.30% (101 runs sampled)
xxhash+seed x 2,028,424 ops/sec ±0.07% (104 runs sampled)
Using key of length 10000
murmurhash3 x 200,382 ops/sec ±0.62% (96 runs sampled)
murmurhash3+seed x 201,576 ops/sec ±0.06% (103 runs sampled)
farmhash-hash-switch-string x 405,098 ops/sec ±0.77% (95 runs sampled)
farmhash-hash-switch-buffer x 703,479 ops/sec ±0.06% (101 runs sampled)
farmhash-hash-buffer-only x 1,233,079 ops/sec ±0.11% (100 runs sampled)
farmhash-hash-string-only x 395,867 ops/sec ±0.04% (100 runs sampled)
farmhash-hash+seed-switch-string x 397,470 ops/sec ±0.05% (101 runs sampled)
farmhash-hash+seed-switch-buffer x 711,409 ops/sec ±0.08% (103 runs sampled)
farmhash-hash+seed-string-only x 394,845 ops/sec ±0.05% (98 runs sampled)
farmhash-hash+seed-buffer-only x 1,169,189 ops/sec ±0.04% (103 runs sampled)
farmhash-fingerprint x 224,409 ops/sec ±0.20% (97 runs sampled)
xxhash+seed x 484,341 ops/sec ±1.03% (101 runs sampled)