From de3f4464d63af70fe3a786357f15ec5cb919e56a Mon Sep 17 00:00:00 2001 From: gobwas Date: Mon, 22 Feb 2016 20:23:57 +0300 Subject: [PATCH] add test --- match/btree_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/match/btree_test.go b/match/btree_test.go index 24c10ee..814f715 100644 --- a/match/btree_test.go +++ b/match/btree_test.go @@ -46,3 +46,37 @@ func TestBTree(t *testing.T) { } } } + +type fakeMatcher struct { + len int + name string +} + +func (f *fakeMatcher) Match(string) bool { + return true +} +func (f *fakeMatcher) Index(s string) (int, []int) { + return 0, []int{1} +} +func (f *fakeMatcher) Len() int { + return f.len +} +func (f *fakeMatcher) String() string { + return f.name +} + +func BenchmarkMatchBTree(b *testing.B) { + l := &fakeMatcher{4, "left_fake"} + r := &fakeMatcher{4, "right_fake"} + v := &fakeMatcher{2, "value_fake"} + + // must be <= len(l + r + v) + fixture := "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij" + + bt := NewBTree(v, l, r) + + b.SetParallelism(1) + for i := 0; i < b.N; i++ { + bt.Match(fixture) + } +}