0
0

change collector benchmark to not reuse collector instances

they are never reused in practice
and the original design did not consider reuse
future alternate implementations are not reusable
This commit is contained in:
Marty Schoch 2016-08-24 15:14:40 -04:00
parent 5f1454106d
commit 94489fa778
2 changed files with 8 additions and 5 deletions

View File

@ -10,7 +10,9 @@ import (
"golang.org/x/net/context"
)
func benchHelper(numOfMatches int, collector search.Collector, b *testing.B) {
type createCollector func() search.Collector
func benchHelper(numOfMatches int, cc createCollector, b *testing.B) {
matches := make([]*search.DocumentMatch, 0, numOfMatches)
for i := 0; i < numOfMatches; i++ {
matches = append(matches, &search.DocumentMatch{
@ -25,6 +27,7 @@ func benchHelper(numOfMatches int, collector search.Collector, b *testing.B) {
searcher := &stubSearcher{
matches: matches,
}
collector := cc()
err := collector.Collect(context.Background(), searcher, &stubReader{})
if err != nil {
b.Fatal(err)

View File

@ -402,17 +402,17 @@ func TestPaginationSameScores(t *testing.T) {
}
func BenchmarkTop10of100000Scores(b *testing.B) {
benchHelper(10000, NewTopScorerCollector(10), b)
benchHelper(10000, func() search.Collector { return NewTopScorerCollector(10) }, b)
}
func BenchmarkTop100of100000Scores(b *testing.B) {
benchHelper(10000, NewTopScorerCollector(100), b)
benchHelper(10000, func() search.Collector { return NewTopScorerCollector(100) }, b)
}
func BenchmarkTop10of1000000Scores(b *testing.B) {
benchHelper(100000, NewTopScorerCollector(10), b)
benchHelper(100000, func() search.Collector { return NewTopScorerCollector(10) }, b)
}
func BenchmarkTop100of1000000Scores(b *testing.B) {
benchHelper(100000, NewTopScorerCollector(100), b)
benchHelper(100000, func() search.Collector { return NewTopScorerCollector(100) }, b)
}