我以爲升壓正則表達式引擎會比升壓::算法快
這個簡單的測試顯示算法中被擊敗的正則表達式引擎大幅度增加
這是整個測試計劃
我錯過了什麼嗎?當我應該更喜歡的boost ::正則表達式(或升壓:: xpressive中)在升壓::算法
#include "boost/algorithm/string.hpp"
#include "boost/regex.hpp"
#include "boost/xpressive/xpressive.hpp"
#include "boost/progress.hpp"
#include <iostream>
int main()
{
boost::timer tm;
const int ITERATIONS = 10000000;
{
std::string input("This is his face");
tm.restart();
for(int i = 0; i < ITERATIONS; ++i)
{
boost::algorithm::replace_all(input,"his","her");
}
std::cout << "boost::algorithm: " << tm.elapsed()/60 << std::endl;
}
{
std::string input("This is his face");
boost::regex expr("his");
std::string format("her");
tm.restart();
for(int i = 0; i < ITERATIONS; ++i)
{
boost::regex_replace(input, expr, format);
}
std::cout << "boost::regex: " << tm.elapsed()/60 << std::endl;
}
{
std::string input("This is his face");
boost::xpressive::sregex expr = boost::xpressive::as_xpr("his");
std::string format("her");
tm.restart();
for(int i = 0; i < ITERATIONS; ++i)
{
boost::xpressive::regex_replace(input, expr, format);
}
std::cout << "boost::xpressive: " << tm.elapsed()/60 << std::endl;
}
return 0;
}