Use sqrt(n) chunk size in pod affinity and core scheduler

Kubernetes-commit: e902e70d0d9bca1a1c823ce9d04d8fd68e8f3396
This commit is contained in:
Aldo Culquicondor 2020-03-16 14:12:11 -04:00 committed by Kubernetes Publisher
parent 326ffd9341
commit 7ee24064f0

View File

@ -83,20 +83,13 @@ func BenchmarkParallelizeUntil(b *testing.B) {
b.Run(tc.String(), func(b *testing.B) { b.Run(tc.String(), func(b *testing.B) {
ctx := context.Background() ctx := context.Background()
isPrime := make([]bool, tc.pieces) isPrime := make([]bool, tc.pieces)
b.ResetTimer()
for c := 0; c < b.N; c++ { for c := 0; c < b.N; c++ {
ParallelizeUntil(ctx, tc.workers, tc.pieces, func(p int) { ParallelizeUntil(ctx, tc.workers, tc.pieces, func(p int) {
if p <= 1 { isPrime[p] = calPrime(p)
return
}
isPrime[p] = true
for i := 2; i*i <= p; i++ {
if p%i == 0 {
isPrime[p] = false
return
}
}
}, WithChunkSize(tc.chunkSize)) }, WithChunkSize(tc.chunkSize))
} }
b.StopTimer()
want := []bool{false, false, true, true, false, true, false, true, false, false, false, true} want := []bool{false, false, true, true, false, true, false, true, false, false, false, true}
if diff := cmp.Diff(want, isPrime[:len(want)]); diff != "" { if diff := cmp.Diff(want, isPrime[:len(want)]); diff != "" {
b.Errorf("miscalculated isPrime (-want,+got):\n%s", diff) b.Errorf("miscalculated isPrime (-want,+got):\n%s", diff)
@ -104,3 +97,15 @@ func BenchmarkParallelizeUntil(b *testing.B) {
}) })
} }
} }
func calPrime(p int) bool {
if p <= 1 {
return false
}
for i := 2; i*i <= p; i++ {
if p%i == 0 {
return false
}
}
return true
}