ad2b6ded3b
Benchmark on i7-2600k, which has the POPCNT instruction: name old time/op new time/op delta DistanceIdentical-8 5.08ns ± 0% 1.01ns ± 1% -80.07% (p=0.008 n=5+5) DistanceDifferent-8 81.5ns ± 2% 1.0ns ± 0% -98.76% (p=0.016 n=5+4) Benchmark on Cavium Octeon, a MIPS64 platform with no dedicated instruction: name old time/op new time/op delta DistanceIdentical-2 120ns ± 6% 144ns ± 5% +19.93% (p=0.008 n=5+5) DistanceDifferent-2 656ns ± 4% 144ns ± 4% -78.09% (p=0.008 n=5+5)
14 lines
142 B
Go
14 lines
142 B
Go
// +build !go1.9
|
|
|
|
package goimagehash
|
|
|
|
func popcnt(x uint64) int {
|
|
diff := 0
|
|
for x != 0 {
|
|
diff += int(x & 1)
|
|
x >>= 1
|
|
}
|
|
|
|
return diff
|
|
}
|