mirror of
https://github.com/boostorg/regex.git
synced 2025-07-12 20:06:38 +02:00
for apples-to-apples, add try/catch to time_boost functions, use syntax_option_type::optimize for dynamic xpressive
[SVN r31024]
This commit is contained in:
@ -84,7 +84,7 @@ int handle_argument(const std::string& what)
|
||||
time_pcre = true;
|
||||
#endif
|
||||
#ifdef BOOST_HAS_XPRESSIVE
|
||||
else if(what == "-xpressive")
|
||||
else if(what == "-xpressive" || what == "-dxpr")
|
||||
time_xpressive = true;
|
||||
#endif
|
||||
else if(what == "-all")
|
||||
@ -160,6 +160,9 @@ int show_usage()
|
||||
#endif
|
||||
#ifdef BOOST_HAS_PCRE
|
||||
" -pcre Apply tests to PCRE library\n"
|
||||
#endif
|
||||
#ifdef BOOST_HAS_XPRESSIVE
|
||||
" -dxpr Apply tests to dynamic xpressive library\n"
|
||||
#endif
|
||||
" -all Apply tests to all libraries\n\n"
|
||||
" test options:\n"
|
||||
|
@ -10,6 +10,7 @@
|
||||
*/
|
||||
|
||||
#include "regex_comparison.hpp"
|
||||
#include <iostream>
|
||||
#include <boost/timer.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
@ -17,37 +18,44 @@ namespace b{
|
||||
|
||||
double time_match(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::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::regex_match(text, what, e);
|
||||
}
|
||||
result = tim.elapsed();
|
||||
iter *= 2;
|
||||
}while(result < 0.5);
|
||||
iter /= 2;
|
||||
try{
|
||||
boost::regex e(re, (icase ? boost::regex::perl | boost::regex::icase : boost::regex::perl));
|
||||
boost::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::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::regex_match(text, what, e);
|
||||
}
|
||||
run = tim.elapsed();
|
||||
result = (std::min)(run, result);
|
||||
}
|
||||
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::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 boost::smatch&)
|
||||
@ -62,42 +70,49 @@ struct noop
|
||||
|
||||
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::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::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();
|
||||
iter *= 2;
|
||||
}while(result < 0.5);
|
||||
iter /= 2;
|
||||
try{
|
||||
boost::regex e(re, (icase ? boost::regex::perl | boost::regex::icase : boost::regex::perl));
|
||||
boost::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::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();
|
||||
iter *= 2;
|
||||
}while(result < 0.5);
|
||||
iter /= 2;
|
||||
|
||||
if(result >10)
|
||||
return result / iter;
|
||||
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::regex_grep(&dummy_grep_proc, text, e);
|
||||
}
|
||||
run = tim.elapsed();
|
||||
result = (std::min)(run, result);
|
||||
}
|
||||
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::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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,11 +22,11 @@ namespace dxpr
|
||||
|
||||
double time_match(const std::string& re, const std::string& text, bool icase)
|
||||
{
|
||||
try{
|
||||
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)));
|
||||
try{
|
||||
boost::xpressive::regex_constants::syntax_option_type flags = boost::xpressive::regex_constants::optimize;
|
||||
if(icase)
|
||||
flags = flags | boost::xpressive::regex_constants::icase;
|
||||
boost::xpressive::sregex e(boost::xpressive::sregex::compile(re, flags));
|
||||
boost::xpressive::smatch what;
|
||||
boost::timer tim;
|
||||
int iter = 1;
|
||||
@ -75,11 +75,11 @@ struct noop
|
||||
|
||||
double time_find_all(const std::string& re, const std::string& text, bool icase)
|
||||
{
|
||||
try{
|
||||
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)));
|
||||
try{
|
||||
boost::xpressive::regex_constants::syntax_option_type flags = boost::xpressive::regex_constants::optimize;
|
||||
if(icase)
|
||||
flags = flags | boost::xpressive::regex_constants::icase;
|
||||
boost::xpressive::sregex e(boost::xpressive::sregex::compile(re, flags));
|
||||
boost::xpressive::smatch what;
|
||||
boost::timer tim;
|
||||
int iter = 1;
|
||||
@ -115,12 +115,12 @@ double time_find_all(const std::string& re, const std::string& text, bool icase)
|
||||
result = (std::min)(run, result);
|
||||
}
|
||||
return result / iter;
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
std::cout << "Exception: " << e.what() << std::endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
std::cout << "Exception: " << e.what() << std::endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user