From 7ee24064f0ea80bc727beb5a75ee3b94311abfd9 Mon Sep 17 00:00:00 2001 From: Aldo Culquicondor Date: Mon, 16 Mar 2020 14:12:11 -0400 Subject: [PATCH] Use sqrt(n) chunk size in pod affinity and core scheduler Kubernetes-commit: e902e70d0d9bca1a1c823ce9d04d8fd68e8f3396 --- util/workqueue/parallelizer_test.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/util/workqueue/parallelizer_test.go b/util/workqueue/parallelizer_test.go index 07362268..24438346 100644 --- a/util/workqueue/parallelizer_test.go +++ b/util/workqueue/parallelizer_test.go @@ -83,20 +83,13 @@ func BenchmarkParallelizeUntil(b *testing.B) { b.Run(tc.String(), func(b *testing.B) { ctx := context.Background() isPrime := make([]bool, tc.pieces) + b.ResetTimer() for c := 0; c < b.N; c++ { ParallelizeUntil(ctx, tc.workers, tc.pieces, func(p int) { - if p <= 1 { - return - } - isPrime[p] = true - for i := 2; i*i <= p; i++ { - if p%i == 0 { - isPrime[p] = false - return - } - } + isPrime[p] = calPrime(p) }, WithChunkSize(tc.chunkSize)) } + b.StopTimer() want := []bool{false, false, true, true, false, true, false, true, false, false, false, true} if diff := cmp.Diff(want, isPrime[:len(want)]); 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 +}