From 9c33f392e68e11e9fa8788bbaaa554750624ffef Mon Sep 17 00:00:00 2001 From: Cyril Tovena Date: Mon, 11 Oct 2021 09:45:02 +0200 Subject: [PATCH] Better benchmarks values. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` ❯ benchcmp before.txt after.txt benchmark old ns/op new ns/op delta BenchmarkNewFastRegexMatcher/(foo|bar)-16 2487 2520 +1.33% BenchmarkNewFastRegexMatcher/foo.*-16 8856 4531 -48.84% BenchmarkNewFastRegexMatcher/.*foo-16 25195 6389 -74.64% BenchmarkNewFastRegexMatcher/^.*foo$-16 25626 6253 -75.60% BenchmarkNewFastRegexMatcher/^.+foo$-16 25429 6248 -75.43% BenchmarkNewFastRegexMatcher/.*-16 429707 8439 -98.04% BenchmarkNewFastRegexMatcher/.+-16 380165 8503 -97.76% BenchmarkNewFastRegexMatcher/foo.+-16 8180 4586 -43.94% BenchmarkNewFastRegexMatcher/.+foo-16 25214 6255 -75.19% BenchmarkNewFastRegexMatcher/foo_.+-16 8116 4334 -46.60% BenchmarkNewFastRegexMatcher/foo_.*-16 8354 4287 -48.68% BenchmarkNewFastRegexMatcher/.*foo.*-16 206076 19227 -90.67% BenchmarkNewFastRegexMatcher/.+foo.+-16 208434 18793 -90.98% BenchmarkNewFastRegexMatcher/#00-16 33045 3936 -88.09% BenchmarkNewFastRegexMatcher/(?s:.*)-16 403806 4208 -98.96% BenchmarkNewFastRegexMatcher/(?s:.+)-16 418177 4150 -99.01% BenchmarkNewFastRegexMatcher/(?s:^.*foo$)-16 24452 5661 -76.85% BenchmarkNewFastRegexMatcher/^(?i:foo|oo)|(bar)$-16 48087 23183 -51.79% BenchmarkNewFastRegexMatcher/((.*)(bar|b|buzz)(.+)|foo)$-16 645430 47193 -92.69% BenchmarkNewFastRegexMatcher/^$-16 37244 3912 -89.50% BenchmarkNewFastRegexMatcher/(prometheus|api_prom)_api_v1_.+-16 17205 10006 -41.84% BenchmarkNewFastRegexMatcher/10\.0\.(1|2)\.+-16 6776 7011 +3.47% BenchmarkNewFastRegexMatcher/10\.0\.(1|2).+-16 14792 4674 -68.40% BenchmarkNewFastRegexMatcher/((fo(bar))|.+foo)-16 497007 17410 -96.50% ``` Signed-off-by: Cyril Tovena --- pkg/labels/regexp.go | 4 ++-- pkg/labels/regexp_test.go | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/labels/regexp.go b/pkg/labels/regexp.go index fb684430c6..a7ba0a5946 100644 --- a/pkg/labels/regexp.go +++ b/pkg/labels/regexp.go @@ -410,10 +410,10 @@ type anyStringMatcher struct { } func (m *anyStringMatcher) Matches(s string) bool { - if !m.matchNL && strings.ContainsRune(s, '\n') { + if !m.allowEmpty && len(s) == 0 { return false } - if !m.allowEmpty && len(s) == 0 { + if !m.matchNL && strings.ContainsRune(s, '\n') { return false } return true diff --git a/pkg/labels/regexp_test.go b/pkg/labels/regexp_test.go index a2193d9481..6e39b9ed7a 100644 --- a/pkg/labels/regexp_test.go +++ b/pkg/labels/regexp_test.go @@ -82,8 +82,14 @@ func TestNewFastRegexMatcher(t *testing.T) { } func BenchmarkNewFastRegexMatcher(b *testing.B) { - benchValues := append(values, - RandStringRunes(128), RandStringRunes(256), RandStringRunes(1024)) + benchValues := values + for _, v := range values { + for i := 5; i < 50; i = i + 5 { + benchValues = append(benchValues, v+RandStringRunes(i)) + benchValues = append(benchValues, RandStringRunes(i)+v+RandStringRunes(i)) + benchValues = append(benchValues, RandStringRunes(i)+v) + } + } for _, r := range regexes { r := r b.Run(r, func(b *testing.B) {