From edaf1d1ec9824bb4fcf59381df91e0f287beeeec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=BF=97=E6=B6=9B?= Date: Wed, 31 Aug 2022 11:10:29 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=AF=B9rure=5F?= =?UTF-8?q?find=E5=92=8Crure=5Fis=5Fmatch=E7=9B=B4=E6=8E=A5=E6=B5=8B?= =?UTF-8?q?=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 | 67 ++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 18 deletions(-) diff --git a/re2/testing/regexp_benchmark.cc b/re2/testing/regexp_benchmark.cc index 4c276e9..7cb63d7 100644 --- a/re2/testing/regexp_benchmark.cc +++ b/re2/testing/regexp_benchmark.cc @@ -28,6 +28,11 @@ #include "util/mutex.h" #include "util/pcre.h" +extern "C" +{ +#include +} + namespace re2 { void Test(); void MemoryUsage(); @@ -578,49 +583,75 @@ void FullMatchRE2(benchmark::State& state, const char *regexp) { state.SetBytesProcessed(state.iterations() * state.range(0)); } -void FullMatchPCRE_LiuZhitao(benchmark::State& state, const char *regexp) { +void FullMatchRE2_LiuZhitao(benchmark::State& state, const char *regexp) { std::ifstream in("re2/testing/text_re2_1KB.txt"); std::stringstream buffer; buffer << in.rdbuf(); std::string s = buffer.str(); - PCRE re(regexp); + RE2 re(regexp, RE2::Latin1); for (auto _ : state) { - CHECK(PCRE::FullMatch(s.substr(0, state.range(0)), re)); + CHECK(RE2::FullMatch(s.substr(0, state.range(0)), re)); } state.SetBytesProcessed(state.iterations() * state.range(0)); } -void FullMatchRE2_LiuZhitao(benchmark::State& state, const char *regexp) { +void Rure_Find_RE2(benchmark::State& state, const char *regexp) +{ + std::ifstream in("/home/freekeeper/Desktop/re2-rust/re2/testing/text_re2_1KB.txt"); + std::stringstream buffer; + buffer << in.rdbuf(); + std::string s = buffer.str().substr(0, state.range(0)); + RE2 re(regexp); + rure_error *err = rure_error_new(); + rure *re1 = rure_compile((const uint8_t *)regexp, strlen(regexp), RURE_DEFAULT_FLAGS, NULL, err); + rure_match match = {0}; + for (auto _ : state) { + bool matched = rure_find(re1, (const uint8_t *)s.c_str(), strlen(s.c_str()), 0, &match); + CHECK(matched); + } + state.SetBytesProcessed(state.iterations() * state.range(0)); +} - std::ifstream in("re2/testing/text_re2_1KB.txt"); +void Rure_is_Match_RE2(benchmark::State& state, const char *regexp) +{ + std::ifstream in("/home/freekeeper/Desktop/re2-rust/re2/testing/text_re2_1KB.txt"); std::stringstream buffer; buffer << in.rdbuf(); - std::string s = buffer.str(); - RE2 re(regexp, RE2::Latin1); + std::string s = buffer.str().substr(0, state.range(0)); + RE2 re(regexp); + rure_error *err = rure_error_new(); + rure *re1 = rure_compile((const uint8_t *)regexp, strlen(regexp), RURE_DEFAULT_FLAGS, NULL, err); for (auto _ : state) { - CHECK(RE2::FullMatch(s.substr(0, state.range(0)), re)); + bool matched = rure_is_match(re1, (const uint8_t *)s.c_str(), strlen(s.c_str()), 0); + CHECK(matched); } state.SetBytesProcessed(state.iterations() * state.range(0)); } +void Rure_Find_RE2_Bench1(benchmark::State& state) { Rure_Find_RE2(state, "(?s).*"); } +void Rure_Find_RE2_Bench2(benchmark::State& state) { Rure_Find_RE2(state, "(?s).*$"); } +void Rure_Find_RE2_Bench3(benchmark::State& state) { Rure_Find_RE2(state, "(?s)((.*)()()($))"); } -void FullMatch_DotStar_CachedPCRE_LiuZhitao(benchmark::State& state) { FullMatchPCRE_LiuZhitao(state, "(?s).*"); } -void FullMatch_DotStar_CachedRE2_LiuZhitao(benchmark::State& state) { FullMatchRE2_LiuZhitao(state, "(?s).*"); } +BENCHMARK_RANGE(Rure_Find_RE2_Bench1, 2<<6, 2<<9); +BENCHMARK_RANGE(Rure_Find_RE2_Bench2, 2<<6, 2<<9); +BENCHMARK_RANGE(Rure_Find_RE2_Bench3, 2<<6, 2<<9); -void FullMatch_DotStarDollar_CachedPCRE_LiuZhitao(benchmark::State& state) { FullMatchPCRE_LiuZhitao(state, "(?s).*$"); } -void FullMatch_DotStarDollar_CachedRE2_LiuZhitao(benchmark::State& state) { FullMatchRE2_LiuZhitao(state, "(?s).*$"); } +void Rure_is_Match_RE2_Bench1(benchmark::State& state) { Rure_is_Match_RE2(state, "(?s).*"); } +void Rure_is_Match_RE2_Bench2(benchmark::State& state) { Rure_is_Match_RE2(state, "(?s).*$"); } +void Rure_is_Match_RE2_Bench3(benchmark::State& state) { Rure_is_Match_RE2(state, "(?s)((.*)()()($))"); } -void FullMatch_DotStarCapture_CachedPCRE_LiuZhitao(benchmark::State& state) { FullMatchPCRE_LiuZhitao(state, "(?s)((.*)()()($))"); } +BENCHMARK_RANGE(Rure_is_Match_RE2_Bench1, 2<<6, 2<<9); +BENCHMARK_RANGE(Rure_is_Match_RE2_Bench2, 2<<6, 2<<9); +BENCHMARK_RANGE(Rure_is_Match_RE2_Bench3, 2<<6, 2<<9); + + +void FullMatch_DotStar_CachedRE2_LiuZhitao(benchmark::State& state) { FullMatchRE2_LiuZhitao(state, "(?s).*"); } +void FullMatch_DotStarDollar_CachedRE2_LiuZhitao(benchmark::State& state) { FullMatchRE2_LiuZhitao(state, "(?s).*$"); } void FullMatch_DotStarCapture_CachedRE2_LiuZhitao(benchmark::State& state) { FullMatchRE2_LiuZhitao(state, "(?s)((.*)()()($))"); } -// BENCHMARK_RANGE(FullMatch_DotStar_CachedPCRE_LiuZhitao, 2<<9, 2<<9); BENCHMARK_RANGE(FullMatch_DotStar_CachedRE2_LiuZhitao, 8, 2<<9); - -// BENCHMARK_RANGE(FullMatch_DotStarDollar_CachedPCRE_LiuZhitao, 2<<9, 2<<9); BENCHMARK_RANGE(FullMatch_DotStarDollar_CachedRE2_LiuZhitao, 8, 2<<9); - -// BENCHMARK_RANGE(FullMatch_DotStarCapture_CachedPCRE_LiuZhitao, 2<<9, 2<<9); BENCHMARK_RANGE(FullMatch_DotStarCapture_CachedRE2_LiuZhitao, 8, 2<<9); void FullMatch_DotStar_CachedPCRE(benchmark::State& state) { FullMatchPCRE(state, "(?s).*"); } -- Gitee From e6a744eee9a94a01d69475998aa601d6c12df6b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=BF=97=E6=B6=9B?= Date: Wed, 31 Aug 2022 11:13:12 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E5=B0=86=E6=B5=8B=E8=AF=95=E6=96=87?= =?UTF-8?q?=E6=9C=AC=E8=B7=AF=E5=BE=84=E7=94=B1=E7=BB=9D=E5=AF=B9=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E6=94=B9=E4=B8=BA=E7=9B=B8=E5=AF=B9=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 刘志涛 --- re2/testing/regexp_benchmark.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/re2/testing/regexp_benchmark.cc b/re2/testing/regexp_benchmark.cc index 7cb63d7..c2e9b50 100644 --- a/re2/testing/regexp_benchmark.cc +++ b/re2/testing/regexp_benchmark.cc @@ -598,7 +598,7 @@ void FullMatchRE2_LiuZhitao(benchmark::State& state, const char *regexp) { void Rure_Find_RE2(benchmark::State& state, const char *regexp) { - std::ifstream in("/home/freekeeper/Desktop/re2-rust/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)); @@ -615,7 +615,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("/home/freekeeper/Desktop/re2-rust/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