Browse Source

Add store set/collect benchmark.

Dmitry Chestnykh 14 năm trước cách đây
mục cha
commit
62d3514ca0
1 tập tin đã thay đổi với 18 bổ sung0 xóa
  1. 18 0
      store_test.go

+ 18 - 0
store_test.go

@@ -57,3 +57,21 @@ func TestCollect(t *testing.T) {
 		t.Errorf("= not collected %d out of %d captchas", nc, len(ids))
 	}
 }
+
+
+func BenchmarkSetCollect(b *testing.B) {
+	b.StopTimer()
+	d := RandomDigits(10)
+	s := NewMemoryStore(9999, -1)
+	ids := make([]string, 1000)
+	for i := range ids {
+		ids[i] = uniuri.New()
+	}
+	b.StartTimer()
+	for i := 0; i < b.N; i++ {
+		for j := 0; j < 1000; j++ {
+			s.Set(ids[j], d)
+		}
+		s.(*memoryStore).collect()
+	}
+}