merged changes in regex5 branch

[SVN r26692]
This commit is contained in:
John Maddock
2005-01-13 17:06:21 +00:00
parent de0ab9092a
commit 71a0e020e2
275 changed files with 37305 additions and 27154 deletions

View File

@ -2,7 +2,7 @@
subproject libs/regex/performance ;
SOURCES = command_line main time_boost time_greta time_localised_boost time_pcre time_posix time_safe_greta ;
SOURCES = command_line main time_boost time_greta time_localised_boost time_pcre time_dynamic_xpressive time_posix time_safe_greta ;
if $(HS_REGEX_PATH)
{
@ -42,3 +42,4 @@ exe regex_comparison :

View File

@ -33,6 +33,7 @@ bool time_greta = false;
bool time_safe_greta = false;
bool time_posix = false;
bool time_pcre = false;
bool time_xpressive = false;
bool test_matches = false;
bool test_code = false;
@ -79,6 +80,10 @@ int handle_argument(const std::string& what)
#ifdef BOOST_HAS_PCRE
else if(what == "-pcre")
time_pcre = true;
#endif
#ifdef BOOST_HAS_XPRESSIVE
else if(what == "-xpressive")
time_xpressive = true;
#endif
else if(what == "-all")
{

View File

@ -65,6 +65,14 @@ void test_match(const std::string& re, const std::string& text, const std::strin
r.pcre_time = time;
std::cout << "\tPCRE regex: " << time << "s\n";
}
#endif
#ifdef BOOST_HAS_XPRESSIVE
if(time_xpressive == true)
{
time = dxpr::time_match(re, text, icase);
r.xpressive_time = time;
std::cout << "\txpressive regex: " << time << "s\n";
}
#endif
r.finalise();
result_list.push_back(r);
@ -118,6 +126,14 @@ void test_find_all(const std::string& re, const std::string& text, const std::st
r.pcre_time = time;
std::cout << "\tPCRE regex: " << time << "s\n";
}
#endif
#ifdef BOOST_HAS_XPRESSIVE
if(time_xpressive == true)
{
time = dxpr::time_find_all(re, text, icase);
r.xpressive_time = time;
std::cout << "\txpressive regex: " << time << "s\n";
}
#endif
r.finalise();
result_list.push_back(r);

View File

@ -26,6 +26,7 @@ extern bool time_greta;
extern bool time_safe_greta;
extern bool time_posix;
extern bool time_pcre;
extern bool time_xpressive;
extern bool test_matches;
extern bool test_short_twain;
@ -53,6 +54,7 @@ struct results
double safe_greta_time;
double posix_time;
double pcre_time;
double xpressive_time;
double factor;
std::string expression;
std::string description;
@ -63,7 +65,8 @@ struct results
safe_greta_time(-1),
posix_time(-1),
pcre_time(-1),
factor((std::numeric_limits<double>::max)()),
xpressive_time(-1),
factor(std::numeric_limits<double>::max()),
expression(ex),
description(desc)
{}
@ -81,6 +84,8 @@ struct results
factor = posix_time;
if((pcre_time >= 0) && (pcre_time < factor))
factor = pcre_time;
if((xpressive_time >= 0) && (xpressive_time < factor))
factor = xpressive_time;
}
};
@ -123,6 +128,12 @@ 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 dxpr {
// 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);
inline void test_match(const std::string& re, const std::string& text, bool icase = false)

View File

@ -45,7 +45,7 @@ double time_match(const std::string& re, const std::string& text, bool icase)
boost::regex_match(text, what, e);
}
run = tim.elapsed();
result = (std::min)(run, result);
result = std::min(run, result);
}
return result / iter;
}
@ -86,7 +86,7 @@ double time_find_all(const std::string& re, const std::string& text, bool icase)
boost::regex_grep(&dummy_grep_proc, text, e);
}
run = tim.elapsed();
result = (std::min)(run, result);
result = std::min(run, result);
}
return result / iter;
}

View File

@ -0,0 +1,129 @@
/*
*
* Copyright (c) 2002
* Dr John Maddock
*
* All rights reserved.
* May not be transfered or disclosed to a third party without
* prior consent of the author.
*
*/
#include "regex_comparison.hpp"
#ifdef BOOST_HAS_XPRESSIVE
#include <cassert>
#include <boost/timer.hpp>
#include <boost/xpressive/xpressive.hpp>
namespace dxpr
{
double time_match(const std::string& re, const std::string& text, bool icase)
{
boost::xpressive::sregex e;
e = (icase ?
boost::xpressive::sregex(boost::xpressive::sregex::compile(re))
: boost::xpressive::sregex(boost::xpressive::sregex::compile(re, boost::xpressive::regex_constants::icase)));
boost::xpressive::smatch what;
boost::timer tim;
int iter = 1;
int counter, repeats;
double result = 0;
double run;
assert(boost::xpressive::regex_match( text, what, e ));
do
{
tim.restart();
for(counter = 0; counter < iter; ++counter)
{
boost::xpressive::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)
{
boost::xpressive::regex_match( text, what, e );
}
run = tim.elapsed();
result = (std::min)(run, result);
}
return result / iter;
}
struct noop
{
void operator()( boost::xpressive::smatch const & ) const
{
}
};
double time_find_all(const std::string& re, const std::string& text, bool icase)
{
boost::xpressive::sregex e;
e = (icase ?
boost::xpressive::sregex(boost::xpressive::sregex::compile(re))
: boost::xpressive::sregex(boost::xpressive::sregex::compile(re, boost::xpressive::regex_constants::icase)));
boost::xpressive::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)
{
boost::xpressive::sregex_iterator begin( text.begin(), text.end(), e ), end;
std::for_each( begin, end, noop() );
}
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)
{
boost::xpressive::sregex_iterator begin( text.begin(), text.end(), e ), end;
std::for_each( begin, end, noop() );
}
run = tim.elapsed();
result = (std::min)(run, result);
}
return result / iter;
}
}
#else
namespace dxpr{
double time_match(const std::string& re, const std::string& text, bool icase)
{
return -1;
}
double time_find_all(const std::string& re, const std::string& text, bool icase)
{
return -1;
}
}
#endif

View File

@ -48,7 +48,7 @@ double time_match(const std::string& re, const std::string& text, bool icase)
e.match(text, what);
}
run = tim.elapsed();
result = (std::min)(run, result);
result = std::min(run, result);
}
return result / iter;
}
@ -94,7 +94,7 @@ double time_find_all(const std::string& re, const std::string& text, bool icase)
}
}
run = tim.elapsed();
result = (std::min)(run, result);
result = std::min(run, result);
}
return result / iter;
}

View File

@ -45,7 +45,7 @@ double time_match(const std::string& re, const std::string& text, bool icase)
boost::regex_match(text, what, e);
}
run = tim.elapsed();
result = (std::min)(run, result);
result = std::min(run, result);
}
return result / iter;
}
@ -86,7 +86,7 @@ double time_find_all(const std::string& re, const std::string& text, bool icase)
boost::regex_grep(&dummy_grep_proc, text, e);
}
run = tim.elapsed();
result = (std::min)(run, result);
result = std::min(run, result);
}
return result / iter;
}

View File

@ -69,7 +69,7 @@ double time_match(const std::string& re, const std::string& text, bool icase)
erroffset = pcre_exec(ppcre, pe, text.c_str(), text.size(), 0, 0, what, sizeof(what)/sizeof(int));
}
run = tim.elapsed();
result = (std::min)(run, result);
result = std::min(run, result);
}
free(ppcre);
free(pe);
@ -152,7 +152,7 @@ double time_find_all(const std::string& re, const std::string& text, bool icase)
}
}
run = tim.elapsed();
result = (std::min)(run, result);
result = std::min(run, result);
}
return result / iter;
}

View File

@ -27,7 +27,7 @@ double time_match(const std::string& re, const std::string& text, bool icase)
int counter, repeats;
double result = 0;
double run;
if(0 != regcomp(&e, re.c_str(), (icase ? REG_ICASE | REG_EXTENDED : REG_EXTENDED)))
if(0 != ::regcomp(&e, re.c_str(), (icase ? REG_ICASE | REG_EXTENDED : REG_EXTENDED)))
return -1;
do
{
@ -50,7 +50,7 @@ double time_match(const std::string& re, const std::string& text, bool icase)
regexec(&e, text.c_str(), e.re_nsub, what, 0);
}
run = tim.elapsed();
result = (std::min)(run, result);
result = std::min(run, result);
}
regfree(&e);
return result / iter;
@ -116,7 +116,7 @@ double time_find_all(const std::string& re, const std::string& text, bool icase)
}
}
run = tim.elapsed();
result = (std::min)(run, result);
result = std::min(run, result);
}
return result / iter;
}

View File

@ -49,7 +49,7 @@ double time_match(const std::string& re, const std::string& text, bool icase)
e.match(text, what);
}
run = tim.elapsed();
result = (std::min)(run, result);
result = std::min(run, result);
}
return result / iter;
}
@ -96,7 +96,7 @@ double time_find_all(const std::string& re, const std::string& text, bool icase)
}
}
run = tim.elapsed();
result = (std::min)(run, result);
result = std::min(run, result);
}
return result / iter;
}