From 7284c10020d0a4a10db2ee48e9160c19b823c271 Mon Sep 17 00:00:00 2001 From: Marty Schoch Date: Fri, 6 Mar 2015 12:59:44 -0500 Subject: [PATCH] added benchmark to collector --- search/collectors/collector_top_score_test.go | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/search/collectors/collector_top_score_test.go b/search/collectors/collector_top_score_test.go index 6f241829..d70ee6c3 100644 --- a/search/collectors/collector_top_score_test.go +++ b/search/collectors/collector_top_score_test.go @@ -10,6 +10,8 @@ package collectors import ( + "math/rand" + "strconv" "testing" "github.com/blevesearch/bleve/search" @@ -213,3 +215,26 @@ func TestTop10ScoresSkip10(t *testing.T) { t.Errorf("expected highest score to be 9.5ß, got %f", results[0].Score) } } + +func BenchmarkTop10of100000Scores(b *testing.B) { + + matches := make(search.DocumentMatchCollection, 0, 100000) + for i := 0; i < 100000; i++ { + matches = append(matches, &search.DocumentMatch{ + ID: strconv.Itoa(i), + Score: rand.Float64(), + }) + } + searcher := &stubSearcher{ + matches: matches, + } + + collector := NewTopScorerCollector(10) + b.ResetTimer() + + collector.Collect(searcher) + res := collector.Results() + for _, dm := range res { + b.Logf("%s - %f\n", dm.ID, dm.Score) + } +}