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:
Eric Niebler
2005-09-18 16:31:56 +00:00
parent badb291912
commit ae36194500
3 changed files with 99 additions and 81 deletions

View File

@ -84,7 +84,7 @@ int handle_argument(const std::string& what)
time_pcre = true; time_pcre = true;
#endif #endif
#ifdef BOOST_HAS_XPRESSIVE #ifdef BOOST_HAS_XPRESSIVE
else if(what == "-xpressive") else if(what == "-xpressive" || what == "-dxpr")
time_xpressive = true; time_xpressive = true;
#endif #endif
else if(what == "-all") else if(what == "-all")
@ -160,6 +160,9 @@ int show_usage()
#endif #endif
#ifdef BOOST_HAS_PCRE #ifdef BOOST_HAS_PCRE
" -pcre Apply tests to PCRE library\n" " -pcre Apply tests to PCRE library\n"
#endif
#ifdef BOOST_HAS_XPRESSIVE
" -dxpr Apply tests to dynamic xpressive library\n"
#endif #endif
" -all Apply tests to all libraries\n\n" " -all Apply tests to all libraries\n\n"
" test options:\n" " test options:\n"

View File

@ -10,6 +10,7 @@
*/ */
#include "regex_comparison.hpp" #include "regex_comparison.hpp"
#include <iostream>
#include <boost/timer.hpp> #include <boost/timer.hpp>
#include <boost/regex.hpp> #include <boost/regex.hpp>
@ -17,6 +18,7 @@ namespace b{
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::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));
boost::smatch what; boost::smatch what;
boost::timer tim; boost::timer tim;
@ -49,6 +51,12 @@ double time_match(const std::string& re, const std::string& text, bool icase)
} }
return result / iter; return result / iter;
} }
catch(const std::exception& e)
{
std::cout << "Exception: " << e.what() << std::endl;
return -1;
}
}
bool dummy_grep_proc(const boost::smatch&) bool dummy_grep_proc(const boost::smatch&)
{ return true; } { return true; }
@ -62,6 +70,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::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));
boost::smatch what; boost::smatch what;
boost::timer tim; boost::timer tim;
@ -99,6 +108,12 @@ double time_find_all(const std::string& re, const std::string& text, bool icase)
} }
return result / iter; return result / iter;
} }
catch(const std::exception& e)
{
std::cout << "Exception: " << e.what() << std::endl;
return -1;
}
}
} }

View File

@ -23,10 +23,10 @@ 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{ try{
boost::xpressive::sregex e; boost::xpressive::regex_constants::syntax_option_type flags = boost::xpressive::regex_constants::optimize;
e = (icase ? if(icase)
boost::xpressive::sregex(boost::xpressive::sregex::compile(re)) flags = flags | boost::xpressive::regex_constants::icase;
: boost::xpressive::sregex(boost::xpressive::sregex::compile(re, boost::xpressive::regex_constants::icase))); boost::xpressive::sregex e(boost::xpressive::sregex::compile(re, flags));
boost::xpressive::smatch what; boost::xpressive::smatch what;
boost::timer tim; boost::timer tim;
int iter = 1; int iter = 1;
@ -76,10 +76,10 @@ 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{ try{
boost::xpressive::sregex e; boost::xpressive::regex_constants::syntax_option_type flags = boost::xpressive::regex_constants::optimize;
e = (icase ? if(icase)
boost::xpressive::sregex(boost::xpressive::sregex::compile(re)) flags = flags | boost::xpressive::regex_constants::icase;
: boost::xpressive::sregex(boost::xpressive::sregex::compile(re, boost::xpressive::regex_constants::icase))); boost::xpressive::sregex e(boost::xpressive::sregex::compile(re, flags));
boost::xpressive::smatch what; boost::xpressive::smatch what;
boost::timer tim; boost::timer tim;
int iter = 1; int iter = 1;