Browse Source

add similar benchmarks from firestorm

Marty Schoch 7 years ago
parent
commit
17c64d37c7
2 changed files with 104 additions and 0 deletions
  1. 63 0
      index/upside_down/analysis_test.go
  2. 41 0
      index/upside_down/upside_down_test.go

+ 63 - 0
index/upside_down/analysis_test.go

@@ -0,0 +1,63 @@
+package upside_down
+
+import (
+	"testing"
+
+	"github.com/blevesearch/bleve/analysis/analyzers/standard_analyzer"
+	"github.com/blevesearch/bleve/document"
+	"github.com/blevesearch/bleve/index"
+	"github.com/blevesearch/bleve/index/store/null"
+	"github.com/blevesearch/bleve/registry"
+)
+
+func BenchmarkAnalyze(b *testing.B) {
+
+	cache := registry.NewCache()
+	analyzer, err := cache.AnalyzerNamed(standard_analyzer.Name)
+	if err != nil {
+		b.Fatal(err)
+	}
+
+	s, err := null.New()
+	if err != nil {
+		b.Fatal(err)
+	}
+	analysisQueue := index.NewAnalysisQueue(1)
+	idx := NewUpsideDownCouch(s, analysisQueue)
+
+	d := document.NewDocument("1")
+	f := document.NewTextFieldWithAnalyzer("desc", nil, bleveWikiArticle1K, analyzer)
+	d.AddField(f)
+
+	b.ResetTimer()
+
+	for i := 0; i < b.N; i++ {
+		rv := idx.Analyze(d)
+		if len(rv.Rows) < 92 || len(rv.Rows) > 93 {
+			b.Fatalf("expected 512-13 rows, got %d", len(rv.Rows))
+		}
+	}
+}
+
+var bleveWikiArticle1K = []byte(`Boiling liquid expanding vapor explosion
+From Wikipedia, the free encyclopedia
+See also: Boiler explosion and Steam explosion
+
+Flames subsequent to a flammable liquid BLEVE from a tanker. BLEVEs do not necessarily involve fire.
+
+This article's tone or style may not reflect the encyclopedic tone used on Wikipedia. See Wikipedia's guide to writing better articles for suggestions. (July 2013)
+A boiling liquid expanding vapor explosion (BLEVE, /ˈblɛviː/ blev-ee) is an explosion caused by the rupture of a vessel containing a pressurized liquid above its boiling point.[1]
+Contents  [hide]
+1 Mechanism
+1.1 Water example
+1.2 BLEVEs without chemical reactions
+2 Fires
+3 Incidents
+4 Safety measures
+5 See also
+6 References
+7 External links
+Mechanism[edit]
+
+This section needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed. (July 2013)
+There are three characteristics of liquids which are relevant to the discussion of a BLEVE:`)

+ 41 - 0
index/upside_down/upside_down_test.go

@@ -13,14 +13,18 @@ import (
 	"os"
 	"reflect"
 	"regexp"
+	"strconv"
 	"testing"
 	"time"
 
 	"github.com/blevesearch/bleve/analysis"
+	"github.com/blevesearch/bleve/analysis/analyzers/standard_analyzer"
 	"github.com/blevesearch/bleve/analysis/tokenizers/regexp_tokenizer"
 	"github.com/blevesearch/bleve/document"
 	"github.com/blevesearch/bleve/index"
 	"github.com/blevesearch/bleve/index/store/boltdb"
+	"github.com/blevesearch/bleve/index/store/null"
+	"github.com/blevesearch/bleve/registry"
 )
 
 var testAnalyzer = &analysis.Analyzer{
@@ -1170,3 +1174,40 @@ func TestIndexDocumentFieldTerms(t *testing.T) {
 		t.Errorf("expected field terms: %#v, got: %#v", expectedFieldTerms, fieldTerms)
 	}
 }
+
+func BenchmarkBatch(b *testing.B) {
+
+	cache := registry.NewCache()
+	analyzer, err := cache.AnalyzerNamed(standard_analyzer.Name)
+	if err != nil {
+		b.Fatal(err)
+	}
+
+	s, err := null.New()
+	if err != nil {
+		b.Fatal(err)
+	}
+	analysisQueue := index.NewAnalysisQueue(1)
+	idx := NewUpsideDownCouch(s, analysisQueue)
+	err = idx.Open()
+	if err != nil {
+		b.Fatal(err)
+	}
+
+	batch := index.NewBatch()
+	for i := 0; i < 100; i++ {
+		d := document.NewDocument(strconv.Itoa(i))
+		f := document.NewTextFieldWithAnalyzer("desc", nil, bleveWikiArticle1K, analyzer)
+		d.AddField(f)
+		batch.Update(d)
+	}
+
+	b.ResetTimer()
+
+	for i := 0; i < b.N; i++ {
+		err = idx.Batch(batch)
+		if err != nil {
+			b.Fatal(err)
+		}
+	}
+}