0
0
bleve/search/facet/facet_builder_terms_test.go
Marty Schoch 0eba2a3f0c reduce garbage created while processing facets
previously we parsed/returned large sections of the documents
back index row in order to compute facet information.  this
would require parsing the protobuf of the entire back index row.
unfortunately this creates considerable garbage.

this new version introduces a visitor/callback approach to
working with data inside the back index row.  the benefit
of this approach is that we can let the higher-level code
see values, prior to any copies of data being made or
intermediate garbage being created.  implementations of
the callback must copy any value which they would like to
retain beyond the callback.

NOTE: this approach is duplicates code from the
automatically generated protobuf code

NOTE: this approach assumes that the "field" field be serialized
before the "terms" field.  This is guaranteed by our currently
generated protobuf encoder, and is recommended by the protobuf
spec.  But, decoders SHOULD support them occuring in any order,
which we do not.
2017-03-02 17:00:46 -05:00

73 lines
1.6 KiB
Go

// Copyright (c) 2016 Couchbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package facet
import (
"io/ioutil"
"regexp"
"testing"
)
var terms []string
func init() {
wsRegexp := regexp.MustCompile(`\W+`)
input, err := ioutil.ReadFile("benchmark_data.txt")
if err != nil {
panic(err)
}
terms = wsRegexp.Split(string(input), -1)
}
func BenchmarkTermsFacet10(b *testing.B) {
termsFacetN(b, 10)
}
func BenchmarkTermsFacet100(b *testing.B) {
termsFacetN(b, 100)
}
func BenchmarkTermsFacet1000(b *testing.B) {
termsFacetN(b, 1000)
}
func BenchmarkTermsFacet10000(b *testing.B) {
termsFacetN(b, 10000)
}
// func BenchmarkTermsFacet100000(b *testing.B) {
// termsFacetN(b, 100000)
// }
func termsFacetN(b *testing.B, numTerms int) {
field := "test"
termsLen := len(terms)
tfb := NewTermsFacetBuilder(field, 3)
i := 0
for len(tfb.termsCount) < numTerms && i <= termsLen {
j := i % termsLen
term := terms[j]
tfb.StartDoc()
tfb.UpdateVisitor(field, []byte(term))
tfb.EndDoc()
i++
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
tfb.Result()
}
}