From 7a5dac1f3300c4690b9efdd940de4dd2bea3ccfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=BF=97=E6=B6=9B?= Date: Tue, 1 Nov 2022 13:51:35 +0000 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=AF=B9ANCHOR=5FST?= =?UTF-8?q?ART=E6=83=85=E5=86=B5=E7=9A=84=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=EF=BC=8C=E5=B9=B6=E5=A2=9E=E5=8A=A0=E4=BA=86Set::Matc?= =?UTF-8?q?h()=E5=87=BD=E6=95=B0Set=E9=9B=86=E5=90=88=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E6=AD=A3=E5=88=99=E8=A1=A8=E8=BE=BE=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 刘志涛 --- re2/testing/regexp_benchmark.cc | 75 ++++++++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 11 deletions(-) diff --git a/re2/testing/regexp_benchmark.cc b/re2/testing/regexp_benchmark.cc index 831300d..23332dd 100644 --- a/re2/testing/regexp_benchmark.cc +++ b/re2/testing/regexp_benchmark.cc @@ -425,7 +425,7 @@ void EmptyPartialMatchRE2(benchmark::State& state) { } void EmptyPartialMatchRE2_text_re2_1KB(benchmark::State& state) { - std::ifstream in("re2/testing/text_re2_1KB.txt"); + std::ifstream in("../../re2/testing/text_re2_1KB.txt"); std::stringstream buffer; buffer << in.rdbuf(); std::string s = buffer.str(); @@ -547,7 +547,7 @@ void ASCIIMatchRE2(benchmark::State& state) { } void ASCIIMatchRE2_text_re2_1KB(benchmark::State& state) { - std::ifstream in("re2/testing/text_re2_1KB.txt"); + std::ifstream in("../../re2/testing/text_re2_1KB.txt"); std::stringstream buffer; buffer << in.rdbuf(); std::string s = buffer.str(); @@ -587,7 +587,7 @@ void FullMatchRE2(benchmark::State& state, const char *regexp) { void FullMatchRE2_text_re2_1KB(benchmark::State& state, const char *regexp) { - std::ifstream in("re2/testing/text_re2_1KB.txt"); + std::ifstream in("../../re2/testing/text_re2_1KB.txt"); std::stringstream buffer; buffer << in.rdbuf(); std::string s = buffer.str(); @@ -639,11 +639,14 @@ void FullMatchRE2_text_dotnl_90(benchmark::State& state, const char *regexp) { void Set_Match_UNANCHORED_NULL_RE2(benchmark::State& state) { - std::ifstream in("re2/testing/text_re2_1KB.txt"); + 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("(?s).*", NULL); + s.Add("(?s).*$", NULL); + s.Add("(?s)((.*)()()($))", NULL); s.Add("hwx", NULL); s.Add("ldi", NULL); s.Compile(); @@ -656,11 +659,14 @@ 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::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("(?s).*", NULL); + s.Add("(?s).*$", NULL); + s.Add("(?s)((.*)()()($))", NULL); s.Add("hwx", NULL); s.Add("ldi", NULL); s.Compile(); @@ -674,12 +680,15 @@ 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::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("(?s).*", NULL); + s.Add("(?s).*$", NULL); + s.Add("(?s)((.*)()()($))", NULL); + s.Add("hwx", NULL); s.Add("ldi", NULL); s.Compile(); for (auto _ : state) { @@ -691,12 +700,15 @@ 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::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("(?s).*", NULL); + s.Add("(?s).*$", NULL); + s.Add("(?s)((.*)()()($))", NULL); + s.Add("hwx", NULL); s.Add("ldi", NULL); s.Compile(); std::vector v; @@ -707,9 +719,50 @@ void Set_Match_ANCHOR_BOTH_RE2(benchmark::State& state) } BENCHMARK_RANGE(Set_Match_ANCHOR_BOTH_RE2, 2 << 6, 2 << 9); +void Set_Match_ANCHOR_START_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_START); + s.Add("(?s).*", NULL); + s.Add("(?s).*$", NULL); + s.Add("(?s)((.*)()()($))", NULL); + 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_ANCHOR_START_NULL_RE2, 2 << 6, 2 << 9); + +void Set_Match_ANCHOR_START_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_START); + s.Add("(?s).*", NULL); + s.Add("(?s).*$", NULL); + s.Add("(?s)((.*)()()($))", NULL); + 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_ANCHOR_START_RE2, 2 << 6, 2 << 9); + void Rure_Find_RE2(benchmark::State& state, const char *regexp) { - std::ifstream in("re2/testing/text_re2_1KB.txt"); + std::ifstream in("../../re2/testing/text_re2_1KB.txt"); std::stringstream buffer; buffer << in.rdbuf(); std::string s = buffer.str().substr(0, state.range(0)); @@ -725,7 +778,7 @@ void Rure_Find_RE2(benchmark::State& state, const char *regexp) void Rure_is_Match_RE2(benchmark::State& state, const char *regexp) { - std::ifstream in("re2/testing/text_re2_1KB.txt"); + std::ifstream in("../../re2/testing/text_re2_1KB.txt"); std::stringstream buffer; buffer << in.rdbuf(); std::string s = buffer.str().substr(0, state.range(0)); -- Gitee