mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 19:01:49 +00:00
Speed up counting of bits in allocator
Benchmark: goos: linux goarch: amd64 pkg: k8s.io/kubernetes/pkg/registry/core/service/allocator cpu: Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz Before: BenchmarkCountBits-8 9459236 140.4 ns/op After: BenchmarkCountBits-8 140667842 9.541 ns/op
This commit is contained in:
parent
125312a8cf
commit
21755f9ec0
@ -24,8 +24,8 @@ import (
|
||||
// countBits returns the number of set bits in n
|
||||
func countBits(n *big.Int) int {
|
||||
var count int = 0
|
||||
for _, b := range n.Bytes() {
|
||||
count += bits.OnesCount8(uint8(b))
|
||||
for _, w := range n.Bits() {
|
||||
count += bits.OnesCount64(uint64(w))
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user