Skip to content

Commit 1308eab

Browse files
committed
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)
1 parent 444ad31 commit 1308eab

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

metro64.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,15 @@ func Hash64(buffer []byte, seed uint64) uint64 {
2121
v := [4]uint64{hash, hash, hash, hash}
2222

2323
for len(ptr) >= 32 {
24-
v[0] += binary.LittleEndian.Uint64(ptr) * k0
25-
ptr = ptr[8:]
24+
v[0] += binary.LittleEndian.Uint64(ptr[:8]) * k0
2625
v[0] = rotate_right(v[0], 29) + v[2]
27-
v[1] += binary.LittleEndian.Uint64(ptr) * k1
28-
ptr = ptr[8:]
26+
v[1] += binary.LittleEndian.Uint64(ptr[8:16]) * k1
2927
v[1] = rotate_right(v[1], 29) + v[3]
30-
v[2] += binary.LittleEndian.Uint64(ptr) * k2
31-
ptr = ptr[8:]
28+
v[2] += binary.LittleEndian.Uint64(ptr[16:24]) * k2
3229
v[2] = rotate_right(v[2], 29) + v[0]
33-
v[3] += binary.LittleEndian.Uint64(ptr) * k3
34-
ptr = ptr[8:]
30+
v[3] += binary.LittleEndian.Uint64(ptr[24:32]) * k3
3531
v[3] = rotate_right(v[3], 29) + v[1]
32+
ptr = ptr[32:]
3633
}
3734

3835
v[2] ^= rotate_right(((v[0]+v[3])*k0)+v[1], 37) * k1

0 commit comments

Comments
 (0)