From 3222d377756fc0940b549f57a038bc9ba2716628 Mon Sep 17 00:00:00 2001 From: gobwas Date: Tue, 2 Feb 2016 22:05:56 +0300 Subject: [PATCH 1/5] fix --- match/nothing_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/match/nothing_test.go b/match/nothing_test.go index 1b96c58..ba31036 100644 --- a/match/nothing_test.go +++ b/match/nothing_test.go @@ -34,7 +34,7 @@ func TestNothingIndex(t *testing.T) { } func BenchmarkIndexNothing(b *testing.B) { - m := Max{10} + m := Nothing{} for i := 0; i < b.N; i++ { m.Index(bench_pattern) } From de3f4464d63af70fe3a786357f15ec5cb919e56a Mon Sep 17 00:00:00 2001 From: gobwas Date: Mon, 22 Feb 2016 20:23:57 +0300 Subject: [PATCH 2/5] 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) + } +} From eb46c5146c4ad7b8a379057b9ddac0383b77883e Mon Sep 17 00:00:00 2001 From: gobwas Date: Mon, 22 Feb 2016 22:17:25 +0300 Subject: [PATCH 3/5] test parallel --- match/btree_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/match/btree_test.go b/match/btree_test.go index 814f715..ba8b99b 100644 --- a/match/btree_test.go +++ b/match/btree_test.go @@ -75,8 +75,9 @@ func BenchmarkMatchBTree(b *testing.B) { bt := NewBTree(v, l, r) - b.SetParallelism(1) - for i := 0; i < b.N; i++ { - bt.Match(fixture) - } + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + bt.Match(fixture) + } + }) } From 128b789a4d94b6d4a0c54cf7a2e51e303195e7a9 Mon Sep 17 00:00:00 2001 From: gobwas Date: Mon, 22 Feb 2016 22:21:32 +0300 Subject: [PATCH 4/5] test parallel --- match/btree_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/match/btree_test.go b/match/btree_test.go index ba8b99b..3a96786 100644 --- a/match/btree_test.go +++ b/match/btree_test.go @@ -55,8 +55,15 @@ type fakeMatcher struct { func (f *fakeMatcher) Match(string) bool { return true } + +var i = 3 + func (f *fakeMatcher) Index(s string) (int, []int) { - return 0, []int{1} + 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 From ebd16e044162346d33aca48a92f5c50fad783489 Mon Sep 17 00:00:00 2001 From: gobwas Date: Mon, 22 Feb 2016 22:25:10 +0300 Subject: [PATCH 5/5] ttt --- glob_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/glob_test.go b/glob_test.go index ce55202..766b233 100644 --- a/glob_test.go +++ b/glob_test.go @@ -183,6 +183,15 @@ func BenchmarkAllGlobMismatch(b *testing.B) { _ = m.Match(fixture_all_mismatch) } } +func BenchmarkAllGlobMatchParallel(b *testing.B) { + m, _ := Compile(pattern_all) + + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + _ = m.Match(fixture_all_match) + } + }) +} func BenchmarkAllRegexpMismatch(b *testing.B) { m := regexp.MustCompile(regexp_all) f := []byte(fixture_all_mismatch)