فهرست منبع

add benchmark

Dan Frank 12 سال پیش
والد
کامیت
2d90b47c2a
1فایلهای تغییر یافته به همراه23 افزوده شده و 0 حذف شده
  1. 23 0
      hostpool_test.go

+ 23 - 0
hostpool_test.go

@@ -118,5 +118,28 @@ func TestEpsilonGreedy(t *testing.T) {
 	}
 
 	assert.Equal(t, hitCounts["b"] > hitCounts["a"], true)
+}
+
+func BenchmarkEpsilonGreedy(b *testing.B) {
+	b.StopTimer()
+
+	// Make up some response times
+	zipfDist := rand.NewZipf(rand.New(rand.NewSource(0)), 1.1, 5, 5000)
+	timings := make([]uint64, b.N)
+	for i := 0; i < b.N; i++ {
+		timings[i] = zipfDist.Uint64()
+	}
+
+	// Make the hostpool with a few hosts
+	p := NewEpsilonGreedy([]string{"a", "b"}, 0, &LinearEpsilonValueCalculator{}).(*epsilonGreedyHostPool)
 
+	b.StartTimer()
+	for i := 0; i < b.N; i++ {
+		if i != 0 && i%100 == 0 {
+			p.performEpsilonGreedyDecay()
+		}
+		hostR := p.Get()
+		p.timer = &mockTimer{t: int(timings[i])}
+		hostR.Mark(nil)
+	}
 }