lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master c40b1c2 4/7: Unit-test PCRE (pc-linux-gnu onl


From: Greg Chicares
Subject: [lmi-commits] [lmi] master c40b1c2 4/7: Unit-test PCRE (pc-linux-gnu only) as well as std::regex
Date: Sat, 2 Oct 2021 17:56:49 -0400 (EDT)

branch: master
commit c40b1c287ab6b8cbad7b735f5ed44b8c02378310
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Unit-test PCRE (pc-linux-gnu only) as well as std::regex
    
    Performance comparison for x86_64-pc-linux-gnu:
    
    boost (prior to preceding commit):
    
      early 0:   1.540e-06 s mean;          1 us least of 6495 runs
      early 1:   1.537e-05 s mean;         15 us least of 651 runs
      early 2:   1.327e-05 s mean;         13 us least of 754 runs
      early 3:   9.408e-06 s mean;          9 us least of 1063 runs
    
      late  0:   3.004e-05 s mean;         29 us least of 333 runs
      late  1:   2.051e-04 s mean;        203 us least of 100 runs
      late  2:   1.949e-04 s mean;        193 us least of 100 runs
      late  3:   9.904e-05 s mean;         95 us least of 101 runs
    
      never 0:   1.222e-05 s mean;         11 us least of 819 runs
      never 1:   1.223e-04 s mean;        121 us least of 100 runs
      never 2:   8.507e-05 s mean;         84 us least of 118 runs
      never 3:   6.745e-05 s mean;         62 us least of 149 runs
    
    std::regex and PCRE:
    
      early 0:   1.572e-06 s mean;          1 us least of 6360 runs
      early 1:   8.597e-05 s mean;         84 us least of 117 runs
      early 2:   8.069e-05 s mean;         80 us least of 124 runs
      early 3:   8.101e-05 s mean;         80 us least of 124 runs
      early 4:   1.130e-05 s mean;         11 us least of 885 runs
    
      late  0:   3.000e-05 s mean;         29 us least of 334 runs
      late  1:   1.051e-03 s mean;       1045 us least of 100 runs
      late  2:   9.713e-04 s mean;        746 us least of 100 runs
      late  3:   7.528e-04 s mean;        746 us least of 100 runs
      late  4:   1.219e-04 s mean;        121 us least of 100 runs
    
      never 0:   1.164e-05 s mean;         11 us least of 860 runs
      never 1:   7.562e-04 s mean;        748 us least of 100 runs
      never 2:   7.186e-04 s mean;        717 us least of 100 runs
      never 3:   7.251e-04 s mean;        717 us least of 100 runs
      never 4:   5.526e-05 s mean;         52 us least of 181 runs
    
    Ignore "0" rows, which are non-regex string searches.
    
    Comparing "4" rows to "1", "2", and "3" rows in the first table shows
    that PCRE's performance is of the same order of magnitude as boost's,
    while std::regex (for gcc-10) is uncompetitive.
---
 objects.make   |  1 +
 regex_test.cpp | 35 +++++++++++++++++++++++++++++++++++
 workhorse.make |  8 ++++++++
 3 files changed, 44 insertions(+)

diff --git a/objects.make b/objects.make
index b17a036..3176ac1 100644
--- a/objects.make
+++ b/objects.make
@@ -978,6 +978,7 @@ rate_table_test$(EXEEXT): \
   rate_table.o \
   rate_table_test.o \
 
+regex_test$(EXEEXT): EXTRA_LDFLAGS = $(pcre_ldflags)
 regex_test$(EXEEXT): \
   $(boost_regex_objects) \
   $(common_test_objects) \
diff --git a/regex_test.cpp b/regex_test.cpp
index 23f9ed0..7438991 100644
--- a/regex_test.cpp
+++ b/regex_test.cpp
@@ -25,6 +25,11 @@
 #include "test_tools.hpp"
 #include "timer.hpp"
 
+#if defined LMI_POSIX
+#   include "pcre_regex.hpp"
+#   define TEST_PCRE
+#endif // defined LMI_POSIX
+
 #include <regex>
 #include <sstream>
 #include <string>
@@ -201,6 +206,15 @@ bool contains_regex3(std::string const& regex)
         );
 }
 
+#if defined TEST_PCRE
+/// Match a regex using PCRE2 (with "DOT ALL", like perl's '-s').
+
+bool contains_regex4(std::string const& regex)
+{
+    return pcre::search(text, pcre::regex(regex)) ? true : false;
+}
+#endif // defined TEST_PCRE
+
 void mete_vectorize()
 {
     lines = vectorize(text);
@@ -214,6 +228,9 @@ void mete()
         :1 == Function ? contains_regex1
         :2 == Function ? contains_regex2
         :3 == Function ? contains_regex3
+#if defined TEST_PCRE
+        :4 == Function ? contains_regex4
+#endif // defined TEST_PCRE
         :nullptr
         ;
     f(Regex);
@@ -256,33 +273,51 @@ void test_psalm_37()
     LMI_TEST( contains_regex1(early));
     LMI_TEST( contains_regex2(early));
     LMI_TEST( contains_regex3(early));
+#if defined TEST_PCRE
+    LMI_TEST( contains_regex4(early));
+#endif // defined TEST_PCRE
 
     LMI_TEST( contains_regex0(late ));
     LMI_TEST( contains_regex1(late ));
     LMI_TEST( contains_regex2(late ));
     LMI_TEST( contains_regex3(late ));
+#if defined TEST_PCRE
+    LMI_TEST( contains_regex4(late ));
+#endif // defined TEST_PCRE
 
     LMI_TEST(!contains_regex0(never));
     LMI_TEST(!contains_regex1(never));
     LMI_TEST(!contains_regex2(never));
     LMI_TEST(!contains_regex3(never));
+#if defined TEST_PCRE
+    LMI_TEST(!contains_regex4(never));
+#endif // defined TEST_PCRE
 
     std::cout << "  early 0:   " << TimeAnAliquot(mete<0,early>) << '\n';
     std::cout << "  early 1:   " << TimeAnAliquot(mete<1,early>) << '\n';
     std::cout << "  early 2:   " << TimeAnAliquot(mete<2,early>) << '\n';
     std::cout << "  early 3:   " << TimeAnAliquot(mete<3,early>) << '\n';
+#if defined TEST_PCRE
+    std::cout << "  early 4:   " << TimeAnAliquot(mete<4,early>) << '\n';
+#endif // defined TEST_PCRE
     std::cout << '\n';
 
     std::cout << "  late  0:   " << TimeAnAliquot(mete<0,late >) << '\n';
     std::cout << "  late  1:   " << TimeAnAliquot(mete<1,late >) << '\n';
     std::cout << "  late  2:   " << TimeAnAliquot(mete<2,late >) << '\n';
     std::cout << "  late  3:   " << TimeAnAliquot(mete<3,late >) << '\n';
+#if defined TEST_PCRE
+    std::cout << "  late  4:   " << TimeAnAliquot(mete<4,late >) << '\n';
+#endif // defined TEST_PCRE
     std::cout << '\n';
 
     std::cout << "  never 0:   " << TimeAnAliquot(mete<0,never>) << '\n';
     std::cout << "  never 1:   " << TimeAnAliquot(mete<1,never>) << '\n';
     std::cout << "  never 2:   " << TimeAnAliquot(mete<2,never>) << '\n';
     std::cout << "  never 3:   " << TimeAnAliquot(mete<3,never>) << '\n';
+#if defined TEST_PCRE
+    std::cout << "  never 4:   " << TimeAnAliquot(mete<4,never>) << '\n';
+#endif // defined TEST_PCRE
     std::cout << '\n';
 }
 
diff --git a/workhorse.make b/workhorse.make
index c9e2a2e..a56961b 100644
--- a/workhorse.make
+++ b/workhorse.make
@@ -186,6 +186,14 @@ endif
 
 
################################################################################
 
+# pcre2 library settings (x86_64-pc-linux-gnu only).
+
+ifeq (x86_64-pc-linux-gnu,$(LMI_TRIPLET))
+  pcre_ldflags := $(shell pcre2-config --libs-posix)
+endif
+
+################################################################################
+
 # xml library settings.
 
 # Flags for all other xml libraries are provided by *-config scripts,



reply via email to

[Prev in Thread] Current Thread [Next in Thread]