Permalink
Browse files

speed up pure-Go inner loop by allowing improved bounds check hints

name          old time/op    new time/op    delta
Metro/100-8     28.8ns ± 6%    23.6ns ± 4%  -18.30%  (p=0.000 n=27+28)
Metro/1024-8     158ns ± 6%     118ns ± 5%  -25.58%  (p=0.000 n=30+30)
Metro/8192-8    1.17µs ± 5%    0.88µs ± 7%  -24.73%  (p=0.000 n=30+30)

name          old speed      new speed      delta
Metro/100-8   3.47GB/s ± 6%  4.25GB/s ± 3%  +22.48%  (p=0.000 n=27+27)
Metro/1024-8  6.47GB/s ± 5%  8.68GB/s ± 4%  +34.23%  (p=0.000 n=30+30)
Metro/8192-8  7.03GB/s ± 5%  9.34GB/s ± 6%  +32.86%  (p=0.000 n=30+30)
  • Loading branch information...
dgryski committed Jan 8, 2018
1 parent 444ad31 commit 1308eab584388b3f8f6050f027708891c4f4143a
Showing with 5 additions and 8 deletions.
  1. +5 −8 metro64.go
@@ -21,18 +21,15 @@ func Hash64(buffer []byte, seed uint64) uint64 {
v := [4]uint64{hash, hash, hash, hash}
for len(ptr) >= 32 {
v[0] += binary.LittleEndian.Uint64(ptr) * k0
ptr = ptr[8:]
v[0] += binary.LittleEndian.Uint64(ptr[:8]) * k0
v[0] = rotate_right(v[0], 29) + v[2]
v[1] += binary.LittleEndian.Uint64(ptr) * k1
ptr = ptr[8:]
v[1] += binary.LittleEndian.Uint64(ptr[8:16]) * k1
v[1] = rotate_right(v[1], 29) + v[3]
v[2] += binary.LittleEndian.Uint64(ptr) * k2
ptr = ptr[8:]
v[2] += binary.LittleEndian.Uint64(ptr[16:24]) * k2
v[2] = rotate_right(v[2], 29) + v[0]
v[3] += binary.LittleEndian.Uint64(ptr) * k3
ptr = ptr[8:]
v[3] += binary.LittleEndian.Uint64(ptr[24:32]) * k3
v[3] = rotate_right(v[3], 29) + v[1]
ptr = ptr[32:]
}
v[2] ^= rotate_right(((v[0]+v[3])*k0)+v[1], 37) * k1

1 comment on commit 1308eab

@mrxinu

This comment has been minimized.

mrxinu commented on 1308eab Apr 28, 2018

That's a pretty stellar improvement.

bitmoji

Please sign in to comment.