From 4ed63d033a663f42c1a1031ed973b789940570ef Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 22 Aug 2019 16:35:55 +0300 Subject: [PATCH] lib/storage: add benchmarks for regexp filter match / mismatch These benchmarks allow estimate the performance of regexp filters in promql --- lib/storage/index_db_timing_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/storage/index_db_timing_test.go b/lib/storage/index_db_timing_test.go index 2e88945a92..edf8076b7e 100644 --- a/lib/storage/index_db_timing_test.go +++ b/lib/storage/index_db_timing_test.go @@ -3,6 +3,7 @@ package storage import ( "fmt" "os" + "regexp" "strconv" "sync/atomic" "testing" @@ -11,6 +12,34 @@ import ( "github.com/VictoriaMetrics/VictoriaMetrics/lib/workingsetcache" ) +func BenchmarkRegexpFilterMatch(b *testing.B) { + b.ReportAllocs() + b.RunParallel(func(pb *testing.PB) { + re := regexp.MustCompile(`.*foo-bar-baz.*`) + b := []byte("fdsffd foo-bar-baz assd fdsfad dasf dsa") + for pb.Next() { + if !re.Match(b) { + panic("BUG: regexp must match!") + } + b[0]++ + } + }) +} + +func BenchmarkRegexpFilterMismatch(b *testing.B) { + b.ReportAllocs() + b.RunParallel(func(pb *testing.PB) { + re := regexp.MustCompile(`.*foo-bar-baz.*`) + b := []byte("fdsffd foo-bar sfddsf assd nmn,mfdsdsakj") + for pb.Next() { + if re.Match(b) { + panic("BUG: regexp mustn't match!") + } + b[0]++ + } + }) +} + func BenchmarkIndexDBAddTSIDs(b *testing.B) { const recordsPerLoop = 1e3