From e80b00dc104687a4b957d21251ea431693c7aec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=BF=97=E6=B6=9B?= Date: Sun, 30 Oct 2022 13:36:28 +0000 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E9=92=88=E5=AF=B9se?= =?UTF-8?q?t.cc=E7=9A=84=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 刘志涛 --- re2/testing/regexp_benchmark.cc | 71 +++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/re2/testing/regexp_benchmark.cc b/re2/testing/regexp_benchmark.cc index 23364d5..831300d 100644 --- a/re2/testing/regexp_benchmark.cc +++ b/re2/testing/regexp_benchmark.cc @@ -24,6 +24,7 @@ #include "util/strutil.h" // #include "re2/prog.h" #include "re2/re2.h" +#include "re2/set.h" // #include "re2/regexp.h" #include "util/mutex.h" #include "util/pcre.h" @@ -636,6 +637,76 @@ void FullMatchRE2_text_dotnl_90(benchmark::State& state, const char *regexp) { state.SetBytesProcessed(state.iterations() * state.range(0)); } +void Set_Match_UNANCHORED_NULL_RE2(benchmark::State& state) +{ + std::ifstream in("re2/testing/text_re2_1KB.txt"); + std::stringstream buffer; + buffer << in.rdbuf(); + std::string str = buffer.str().substr(0, state.range(0)); + RE2::Set s(RE2::DefaultOptions, RE2::UNANCHORED); + s.Add("hwx", NULL); + s.Add("ldi", NULL); + s.Compile(); + for (auto _ : state) { + s.Match(str, NULL); + } + state.SetBytesProcessed(state.iterations() * state.range(0)); +} +BENCHMARK_RANGE(Set_Match_UNANCHORED_NULL_RE2, 2 << 6, 2 << 9); + +void Set_Match_UNANCHORED_RE2(benchmark::State& state) +{ + std::ifstream in("re2/testing/text_re2_1KB.txt"); + std::stringstream buffer; + buffer << in.rdbuf(); + std::string str = buffer.str().substr(0, state.range(0)); + RE2::Set s(RE2::DefaultOptions, RE2::UNANCHORED); + s.Add("hwx", NULL); + s.Add("ldi", NULL); + s.Compile(); + std::vector v; + for (auto _ : state) { + s.Match(str, &v); + } + state.SetBytesProcessed(state.iterations() * state.range(0)); +} +BENCHMARK_RANGE(Set_Match_UNANCHORED_RE2, 2 << 6, 2 << 9); + +void Set_Match_ANCHOR_BOTH_NULL_RE2(benchmark::State& state) +{ + std::ifstream in("re2/testing/text_re2_1KB.txt"); + std::stringstream buffer; + buffer << in.rdbuf(); + std::string str = buffer.str().substr(0, state.range(0)); + RE2::Set s(RE2::DefaultOptions, RE2::ANCHOR_BOTH); + s.Add(".*", NULL); + s.Add("ldi", NULL); + s.Compile(); + for (auto _ : state) { + s.Match(str, NULL); + } + state.SetBytesProcessed(state.iterations() * state.range(0)); +} +BENCHMARK_RANGE(Set_Match_ANCHOR_BOTH_NULL_RE2, 2 << 6, 2 << 9); + +void Set_Match_ANCHOR_BOTH_RE2(benchmark::State& state) +{ + std::ifstream in("re2/testing/text_re2_1KB.txt"); + std::stringstream buffer; + buffer << in.rdbuf(); + std::string str = buffer.str().substr(0, state.range(0)); + RE2::Set s(RE2::DefaultOptions, RE2::ANCHOR_BOTH); + s.Add(".*", NULL); + s.Add("ldi", NULL); + s.Compile(); + std::vector v; + for (auto _ : state) { + s.Match(str, &v); + } + state.SetBytesProcessed(state.iterations() * state.range(0)); +} +BENCHMARK_RANGE(Set_Match_ANCHOR_BOTH_RE2, 2 << 6, 2 << 9); + void Rure_Find_RE2(benchmark::State& state, const char *regexp) { std::ifstream in("re2/testing/text_re2_1KB.txt"); -- Gitee