|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r64199 - trunk/libs/regex/performance
From: john_at_[hidden]
Date: 2010-07-20 10:52:18
Author: johnmaddock
Date: 2010-07-20 10:52:17 EDT (Tue, 20 Jul 2010)
New Revision: 64199
URL: http://svn.boost.org/trac/boost/changeset/64199
Log:
Update performance test program to include std::regex.
Added:
trunk/libs/regex/performance/time_std.cpp (contents, props changed)
Text files modified:
trunk/libs/regex/performance/command_line.cpp | 42 ++++++++++++++++++++++++++++++++++++++-
trunk/libs/regex/performance/input.html | 3 +
trunk/libs/regex/performance/main.cpp | 16 +++++++++++++++
trunk/libs/regex/performance/regex_comparison.hpp | 10 +++++++++
4 files changed, 68 insertions(+), 3 deletions(-)
Modified: trunk/libs/regex/performance/command_line.cpp
==============================================================================
--- trunk/libs/regex/performance/command_line.cpp (original)
+++ trunk/libs/regex/performance/command_line.cpp 2010-07-20 10:52:17 EDT (Tue, 20 Jul 2010)
@@ -34,6 +34,7 @@
bool time_posix = false;
bool time_pcre = false;
bool time_xpressive = false;
+bool time_std = false;
bool test_matches = false;
bool test_code = false;
@@ -55,6 +56,7 @@
double posix_total = 0;
double pcre_total = 0;
double xpressive_total = 0;
+double std_total = 0;
unsigned greta_test_count = 0;
unsigned safe_greta_test_count = 0;
unsigned boost_test_count = 0;
@@ -62,6 +64,7 @@
unsigned posix_test_count = 0;
unsigned pcre_test_count = 0;
unsigned xpressive_test_count = 0;
+unsigned std_test_count = 0;
int handle_argument(const std::string& what)
{
@@ -87,6 +90,10 @@
else if(what == "-xpressive" || what == "-dxpr")
time_xpressive = true;
#endif
+#ifndef BOOST_NO_0X_HDR_REGEX
+ else if(what == "-std")
+ time_std = true;
+#endif
else if(what == "-all")
{
time_boost = true;
@@ -104,6 +111,9 @@
#ifdef BOOST_HAS_XPRESSIVE
time_xpressive = true;
#endif
+#ifndef BOOST_NO_0X_HDR_REGEX
+ time_std = true;
+#endif
}
else if(what == "-test-matches")
test_matches = true;
@@ -167,6 +177,9 @@
#ifdef BOOST_HAS_XPRESSIVE
" -dxpr Apply tests to dynamic xpressive library\n"
#endif
+#ifndef BOOST_NO_0X_HDR_REGEX
+ " -std Apply tests to std::regex.\n"
+#endif
" -all Apply tests to all libraries\n\n"
" test options:\n"
" -test-matches Test short matches\n"
@@ -274,6 +287,10 @@
if(time_xpressive == true)
os << "<td><strong>Dynamic Xpressive</strong></td>";
#endif
+#ifndef BOOST_NO_0X_HDR_REGEX
+ if(time_std == true)
+ os << "<td><strong>std::regex</strong></td>";
+#endif
os << "</tr>\n";
//
@@ -307,7 +324,6 @@
}
}
#endif
-#if defined(BOOST_HAS_POSIX)
if(time_boost == true)
{
print_result(os, first->boost_time, first->factor);
@@ -317,7 +333,6 @@
++boost_test_count;
}
}
-#endif
if(time_localised_boost == true)
{
print_result(os, first->localised_boost_time, first->factor);
@@ -358,6 +373,17 @@
}
}
#endif
+#ifndef BOOST_NO_0X_HDR_REGEX
+ if(time_std == true)
+ {
+ print_result(os, first->std_time, first->factor);
+ if(first->std_time > 0)
+ {
+ std_total += first->std_time / first->factor;
+ ++std_test_count;
+ }
+ }
+#endif
os << "</tr>\n";
++first;
}
@@ -430,6 +456,12 @@
os << "<td><strong>Dynamic Xpressive</strong></td>";
}
#endif
+#ifndef BOOST_NO_0X_HDR_REGEX
+ if(time_std == true)
+ {
+ os << "<td><strong>std::regex</strong></td>";
+ }
+#endif
os << "</tr>\n";
//
@@ -446,6 +478,8 @@
if(time_boost == true)
os << "<td>" << (boost_total / boost_test_count) << "</td>\n";
#endif
+ if(time_boost == true)
+ os << "<td>" << (boost_total / boost_test_count) << "</td>\n";
if(time_localised_boost == true)
os << "<td>" << (locale_boost_total / locale_boost_test_count) << "</td>\n";
if(time_posix == true)
@@ -458,6 +492,10 @@
if(time_xpressive == true)
os << "<td>" << (xpressive_total / xpressive_test_count) << "</td>\n";
#endif
+#ifndef BOOST_NO_0X_HDR_REGEX
+ if(time_std == true)
+ os << "<td>" << (std_total / std_test_count) << "</td>\n";
+#endif
os << "</tr>\n";
os << "</table>\n";
return os.str();
Modified: trunk/libs/regex/performance/input.html
==============================================================================
--- trunk/libs/regex/performance/input.html (original)
+++ trunk/libs/regex/performance/input.html 2010-07-20 10:52:17 EDT (Tue, 20 Jul 2010)
@@ -46,7 +46,7 @@
<h3>Comparison 2: Medium Sized Search</h3>
<p>For each of the following regular expressions the time taken to find all
occurrences of the expression within a medium sized English language text was
- measured (the first 50K from mtent12.txt). </p>
+ measured (the first 50K from mtent12.txt - up to the end of Chapter 1). </p>
<P>%short_twain_search%</P>
<H3>Comparison 3: C++ Code Search</H3>
<P>For each of the following regular expressions the time taken to find all
@@ -73,3 +73,4 @@
</body>
</html>
+
Modified: trunk/libs/regex/performance/main.cpp
==============================================================================
--- trunk/libs/regex/performance/main.cpp (original)
+++ trunk/libs/regex/performance/main.cpp 2010-07-20 10:52:17 EDT (Tue, 20 Jul 2010)
@@ -74,6 +74,14 @@
std::cout << "\txpressive regex: " << time << "s\n";
}
#endif
+#ifndef BOOST_NO_0X_HDR_REGEX
+ if(time_std == true)
+ {
+ time = stdr::time_match(re, text, icase);
+ r.std_time = time;
+ std::cout << "\tstd::regex: " << time << "s\n";
+ }
+#endif
r.finalise();
result_list.push_back(r);
}
@@ -135,6 +143,14 @@
std::cout << "\txpressive regex: " << time << "s\n";
}
#endif
+#ifndef BOOST_NO_0X_HDR_REGEX
+ if(time_std == true)
+ {
+ time = stdr::time_find_all(re, text, icase);
+ r.std_time = time;
+ std::cout << "\tstd::regex: " << time << "s\n";
+ }
+#endif
r.finalise();
result_list.push_back(r);
}
Modified: trunk/libs/regex/performance/regex_comparison.hpp
==============================================================================
--- trunk/libs/regex/performance/regex_comparison.hpp (original)
+++ trunk/libs/regex/performance/regex_comparison.hpp 2010-07-20 10:52:17 EDT (Tue, 20 Jul 2010)
@@ -27,6 +27,7 @@
extern bool time_posix;
extern bool time_pcre;
extern bool time_xpressive;
+extern bool time_std;
extern bool test_matches;
extern bool test_short_twain;
@@ -55,6 +56,7 @@
double posix_time;
double pcre_time;
double xpressive_time;
+ double std_time;
double factor;
std::string expression;
std::string description;
@@ -66,6 +68,7 @@
posix_time(-1),
pcre_time(-1),
xpressive_time(-1),
+ std_time(-1),
factor((std::numeric_limits<double>::max)()),
expression(ex),
description(desc)
@@ -86,6 +89,8 @@
factor = pcre_time;
if((xpressive_time >= 0) && (xpressive_time < factor))
factor = xpressive_time;
+ if((std_time >= 0) && (std_time < factor))
+ factor = std_time;
}
};
@@ -133,6 +138,11 @@
double time_match(const std::string& re, const std::string& text, bool icase);
double time_find_all(const std::string& re, const std::string& text, bool icase);
}
+namespace stdr {
+// xpressive tests:
+double time_match(const std::string& re, const std::string& text, bool icase);
+double time_find_all(const std::string& re, const std::string& text, bool icase);
+}
void test_match(const std::string& re, const std::string& text, const std::string& description, bool icase = false);
void test_find_all(const std::string& re, const std::string& text, const std::string& description, bool icase = false);
Added: trunk/libs/regex/performance/time_std.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/regex/performance/time_std.cpp 2010-07-20 10:52:17 EDT (Tue, 20 Jul 2010)
@@ -0,0 +1,123 @@
+/*
+ *
+ * Copyright (c) 2002
+ * John Maddock
+ *
+ * Use, modification and distribution are subject to the
+ * Boost Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+#include "regex_comparison.hpp"
+#ifndef BOOST_NO_0X_HDR_REGEX
+#include <iostream>
+#include <boost/timer.hpp>
+#include <regex>
+
+namespace stdr{
+
+double time_match(const std::string& re, const std::string& text, bool icase)
+{
+ try{
+ std::regex e(re, (icase ? std::regex::ECMAScript | std::regex::icase : std::regex::ECMAScript));
+ std::smatch what;
+ boost::timer tim;
+ int iter = 1;
+ int counter, repeats;
+ double result = 0;
+ double run;
+ do
+ {
+ tim.restart();
+ for(counter = 0; counter < iter; ++counter)
+ {
+ std::regex_match(text, what, e);
+ }
+ result = tim.elapsed();
+ iter *= 2;
+ }while(result < 0.5);
+ iter /= 2;
+
+ // repeat test and report least value for consistency:
+ for(repeats = 0; repeats < REPEAT_COUNT; ++repeats)
+ {
+ tim.restart();
+ for(counter = 0; counter < iter; ++counter)
+ {
+ std::regex_match(text, what, e);
+ }
+ run = tim.elapsed();
+ result = (std::min)(run, result);
+ }
+ return result / iter;
+ }
+ catch(const std::exception& e)
+ {
+ std::cout << "Exception: " << e.what() << std::endl;
+ return -1;
+ }
+}
+
+bool dummy_grep_proc(const std::smatch&)
+{ return true; }
+
+struct noop
+{
+ void operator()( std::smatch const & ) const
+ {
+ }
+};
+
+double time_find_all(const std::string& re, const std::string& text, bool icase)
+{
+ try{
+ std::regex e(re, (icase ? std::regex::ECMAScript | std::regex::icase : std::regex::ECMAScript));
+ std::smatch what;
+ boost::timer tim;
+ int iter = 1;
+ int counter, repeats;
+ double result = 0;
+ double run;
+ do
+ {
+ tim.restart();
+ for(counter = 0; counter < iter; ++counter)
+ {
+ std::sregex_iterator begin( text.begin(), text.end(), e ), end;
+ std::for_each( begin, end, noop() );
+ //std::regex_grep(&dummy_grep_proc, text, e);
+ }
+ result = tim.elapsed();
+ iter *= 2;
+ }while(result < 0.5);
+ iter /= 2;
+
+ if(result >10)
+ return result / iter;
+
+ // repeat test and report least value for consistency:
+ for(repeats = 0; repeats < REPEAT_COUNT; ++repeats)
+ {
+ tim.restart();
+ for(counter = 0; counter < iter; ++counter)
+ {
+ std::sregex_iterator begin( text.begin(), text.end(), e ), end;
+ std::for_each( begin, end, noop() );
+ //std::regex_grep(&dummy_grep_proc, text, e);
+ }
+ run = tim.elapsed();
+ result = (std::min)(run, result);
+ }
+ return result / iter;
+ }
+ catch(const std::exception& e)
+ {
+ std::cout << "Exception: " << e.what() << std::endl;
+ return -1;
+ }
+}
+
+}
+
+#endif
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk