mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-13 22:05:59 +00:00
Adds benchmark test
This commit is contained in:
parent
2c8a156579
commit
21ca6c498a
@ -18,6 +18,7 @@ package workqueue
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -214,6 +215,25 @@ func TestCopyShifting(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkDelayingQueue_AddAfter(b *testing.B) {
|
||||||
|
r := rand.New(rand.NewSource(time.Now().Unix()))
|
||||||
|
|
||||||
|
fakeClock := clock.NewFakeClock(time.Now())
|
||||||
|
q := newDelayingQueue(fakeClock, "")
|
||||||
|
|
||||||
|
// Add items
|
||||||
|
for n := 0; n < b.N; n++ {
|
||||||
|
data := fmt.Sprintf("%d", n)
|
||||||
|
q.AddAfter(data, time.Duration(r.Int63n(int64(10*time.Minute))))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exercise item removal as well
|
||||||
|
fakeClock.Step(11 * time.Minute)
|
||||||
|
for n := 0; n < b.N; n++ {
|
||||||
|
_, _ = q.Get()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func waitForAdded(q DelayingInterface, depth int) error {
|
func waitForAdded(q DelayingInterface, depth int) error {
|
||||||
return wait.Poll(1*time.Millisecond, 10*time.Second, func() (done bool, err error) {
|
return wait.Poll(1*time.Millisecond, 10*time.Second, func() (done bool, err error) {
|
||||||
if q.Len() == depth {
|
if q.Len() == depth {
|
||||||
|
Loading…
Reference in New Issue
Block a user