From 6e346bf8d55da3b611e49ba8612922bdf3fd962a Mon Sep 17 00:00:00 2001 From: gobwas Date: Mon, 22 Feb 2016 22:21:13 +0300 Subject: [PATCH] test parallel --- match/btree_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/match/btree_test.go b/match/btree_test.go index 24c10ee..3a96786 100644 --- a/match/btree_test.go +++ b/match/btree_test.go @@ -46,3 +46,45 @@ func TestBTree(t *testing.T) { } } } + +type fakeMatcher struct { + len int + name string +} + +func (f *fakeMatcher) Match(string) bool { + return true +} + +var i = 3 + +func (f *fakeMatcher) Index(s string) (int, []int) { + seg := make([]int, 0, i) + for x := 0; x < i; x++ { + seg = append(seg, x) + } + return 0, seg +} +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.RunParallel(func(pb *testing.PB) { + for pb.Next() { + bt.Match(fixture) + } + }) +}