Updated to get xpressive tests to run correctly, and to use regex_iterators for searching.

[SVN r31018]
This commit is contained in:
John Maddock
2005-09-18 09:25:14 +00:00
parent 5973f3eb07
commit badb291912
4 changed files with 67 additions and 4 deletions

View File

@ -54,12 +54,14 @@ double boost_total = 0;
double locale_boost_total = 0; double locale_boost_total = 0;
double posix_total = 0; double posix_total = 0;
double pcre_total = 0; double pcre_total = 0;
double xpressive_total = 0;
unsigned greta_test_count = 0; unsigned greta_test_count = 0;
unsigned safe_greta_test_count = 0; unsigned safe_greta_test_count = 0;
unsigned boost_test_count = 0; unsigned boost_test_count = 0;
unsigned locale_boost_test_count = 0; unsigned locale_boost_test_count = 0;
unsigned posix_test_count = 0; unsigned posix_test_count = 0;
unsigned pcre_test_count = 0; unsigned pcre_test_count = 0;
unsigned xpressive_test_count = 0;
int handle_argument(const std::string& what) int handle_argument(const std::string& what)
{ {
@ -261,6 +263,10 @@ void output_html_results(bool show_description, const std::string& tagname)
#ifdef BOOST_HAS_PCRE #ifdef BOOST_HAS_PCRE
if(time_pcre == true) if(time_pcre == true)
os << "<td><strong>PCRE</strong></td>"; os << "<td><strong>PCRE</strong></td>";
#endif
#ifdef BOOST_HAS_XPRESSIVE
if(time_xpressive == true)
os << "<td><strong>Dynamic Xpressive</strong></td>";
#endif #endif
os << "</tr>\n"; os << "</tr>\n";
@ -305,6 +311,7 @@ void output_html_results(bool show_description, const std::string& tagname)
++boost_test_count; ++boost_test_count;
} }
} }
#endif
if(time_localised_boost == true) if(time_localised_boost == true)
{ {
print_result(os, first->localised_boost_time, first->factor); print_result(os, first->localised_boost_time, first->factor);
@ -314,7 +321,6 @@ void output_html_results(bool show_description, const std::string& tagname)
++locale_boost_test_count; ++locale_boost_test_count;
} }
} }
#endif
if(time_posix == true) if(time_posix == true)
{ {
print_result(os, first->posix_time, first->factor); print_result(os, first->posix_time, first->factor);
@ -334,6 +340,17 @@ void output_html_results(bool show_description, const std::string& tagname)
++pcre_test_count; ++pcre_test_count;
} }
} }
#endif
#if defined(BOOST_HAS_XPRESSIVE)
if(time_xpressive == true)
{
print_result(os, first->xpressive_time, first->factor);
if(first->xpressive_time > 0)
{
xpressive_total += first->xpressive_time / first->factor;
++xpressive_test_count;
}
}
#endif #endif
os << "</tr>\n"; os << "</tr>\n";
++first; ++first;
@ -400,6 +417,12 @@ std::string get_averages_table()
{ {
os << "<td><strong>PCRE</strong></td>"; os << "<td><strong>PCRE</strong></td>";
} }
#endif
#ifdef BOOST_HAS_XPRESSIVE
if(time_xpressive == true)
{
os << "<td><strong>Dynamic Xpressive</strong></td>";
}
#endif #endif
os << "</tr>\n"; os << "</tr>\n";
@ -416,14 +439,18 @@ std::string get_averages_table()
#if defined(BOOST_HAS_POSIX) #if defined(BOOST_HAS_POSIX)
if(time_boost == true) if(time_boost == true)
os << "<td>" << (boost_total / boost_test_count) << "</td>\n"; os << "<td>" << (boost_total / boost_test_count) << "</td>\n";
#endif
if(time_localised_boost == true) if(time_localised_boost == true)
os << "<td>" << (locale_boost_total / locale_boost_test_count) << "</td>\n"; os << "<td>" << (locale_boost_total / locale_boost_test_count) << "</td>\n";
#endif
if(time_posix == true) if(time_posix == true)
os << "<td>" << (posix_total / posix_test_count) << "</td>\n"; os << "<td>" << (posix_total / posix_test_count) << "</td>\n";
#if defined(BOOST_HAS_PCRE) #if defined(BOOST_HAS_PCRE)
if(time_pcre == true) if(time_pcre == true)
os << "<td>" << (pcre_total / pcre_test_count) << "</td>\n"; os << "<td>" << (pcre_total / pcre_test_count) << "</td>\n";
#endif
#if defined(BOOST_HAS_XPRESSIVE)
if(time_xpressive == true)
os << "<td>" << (xpressive_total / xpressive_test_count) << "</td>\n";
#endif #endif
os << "</tr>\n"; os << "</tr>\n";
os << "</table>\n"; os << "</table>\n";

View File

@ -53,6 +53,13 @@ double time_match(const std::string& re, const std::string& text, bool icase)
bool dummy_grep_proc(const boost::smatch&) bool dummy_grep_proc(const boost::smatch&)
{ return true; } { return true; }
struct noop
{
void operator()( boost::smatch const & ) const
{
}
};
double time_find_all(const std::string& re, const std::string& text, bool icase) double time_find_all(const std::string& re, const std::string& text, bool icase)
{ {
boost::regex e(re, (icase ? boost::regex::perl | boost::regex::icase : boost::regex::perl)); boost::regex e(re, (icase ? boost::regex::perl | boost::regex::icase : boost::regex::perl));
@ -67,7 +74,9 @@ double time_find_all(const std::string& re, const std::string& text, bool icase)
tim.restart(); tim.restart();
for(counter = 0; counter < iter; ++counter) for(counter = 0; counter < iter; ++counter)
{ {
boost::regex_grep(&dummy_grep_proc, text, e); boost::sregex_iterator begin( text.begin(), text.end(), e ), end;
std::for_each( begin, end, noop() );
//boost::regex_grep(&dummy_grep_proc, text, e);
} }
result = tim.elapsed(); result = tim.elapsed();
iter *= 2; iter *= 2;

View File

@ -13,6 +13,7 @@
#ifdef BOOST_HAS_XPRESSIVE #ifdef BOOST_HAS_XPRESSIVE
#include <cassert> #include <cassert>
#include <iostream>
#include <boost/timer.hpp> #include <boost/timer.hpp>
#include <boost/xpressive/xpressive.hpp> #include <boost/xpressive/xpressive.hpp>
@ -21,6 +22,7 @@ namespace dxpr
double time_match(const std::string& re, const std::string& text, bool icase) double time_match(const std::string& re, const std::string& text, bool icase)
{ {
try{
boost::xpressive::sregex e; boost::xpressive::sregex e;
e = (icase ? e = (icase ?
boost::xpressive::sregex(boost::xpressive::sregex::compile(re)) boost::xpressive::sregex(boost::xpressive::sregex::compile(re))
@ -56,6 +58,12 @@ double time_match(const std::string& re, const std::string& text, bool icase)
result = (std::min)(run, result); result = (std::min)(run, result);
} }
return result / iter; return result / iter;
}
catch(const std::exception& e)
{
std::cout << "Exception: " << e.what() << std::endl;
return -1;
}
} }
struct noop struct noop
@ -67,6 +75,7 @@ struct noop
double time_find_all(const std::string& re, const std::string& text, bool icase) double time_find_all(const std::string& re, const std::string& text, bool icase)
{ {
try{
boost::xpressive::sregex e; boost::xpressive::sregex e;
e = (icase ? e = (icase ?
boost::xpressive::sregex(boost::xpressive::sregex::compile(re)) boost::xpressive::sregex(boost::xpressive::sregex::compile(re))
@ -106,6 +115,12 @@ double time_find_all(const std::string& re, const std::string& text, bool icase)
result = (std::min)(run, result); result = (std::min)(run, result);
} }
return result / iter; return result / iter;
}
catch(const std::exception& e)
{
std::cout << "Exception: " << e.what() << std::endl;
return -1;
}
} }
} }

View File

@ -53,6 +53,13 @@ double time_match(const std::string& re, const std::string& text, bool icase)
bool dummy_grep_proc(const boost::smatch&) bool dummy_grep_proc(const boost::smatch&)
{ return true; } { return true; }
struct noop
{
void operator()( boost::smatch const & ) const
{
}
};
double time_find_all(const std::string& re, const std::string& text, bool icase) double time_find_all(const std::string& re, const std::string& text, bool icase)
{ {
boost::basic_regex<char, boost::cpp_regex_traits<char> > e(re, (icase ? boost::regex::perl | boost::regex::icase : boost::regex::perl)); boost::basic_regex<char, boost::cpp_regex_traits<char> > e(re, (icase ? boost::regex::perl | boost::regex::icase : boost::regex::perl));
@ -67,7 +74,12 @@ double time_find_all(const std::string& re, const std::string& text, bool icase)
tim.restart(); tim.restart();
for(counter = 0; counter < iter; ++counter) for(counter = 0; counter < iter; ++counter)
{ {
boost::regex_grep(&dummy_grep_proc, text, e); boost::regex_iterator<
std::string::const_iterator,
char,
boost::cpp_regex_traits<char> > begin( text.begin(), text.end(), e ), end;
std::for_each( begin, end, noop() );
//boost::regex_grep(&dummy_grep_proc, text, e);
} }
result = tim.elapsed(); result = tim.elapsed();
iter *= 2; iter *= 2;