John Maddock wrote:
Jin Sun wrote:
Can anybody tell me which one has better performance?
Well it depends what you mean :-)
I'd be surprised if there was much difference between the core regex engines: maybe one would be slightly better at some things the other at different things. Where you gain with Boost.Regex is in the ability to write the surrounding code in a compiled language rather than have it interpreted. Whether you succeed in making your app faster as a result will mainly depend on how cunning you are at avoiding unnecessary copying/memory allocations in your code logic: to put it another way, badly written C++ can be the slowest thing around, while well written code can be as fast as any language out there.
Oh, and not all regular expressions are created equal: if the problem is the speed of the regex matching, then it's likely a problem with the regex you're using.
Just my - entirely biased - 2c, John Maddock.
Keeping in mind John's caveats, I find the language shootout website to be an interesting way to compare. Here's a c++ vs perl results: http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=gpp&lang2=perl http://shootout.alioth.debian.org/gp4/benchmark.php?test=regexdna&lang=all The regex-dna test is written using boost-regex and tests out ~2.4 times slower and with a larger memory footprint than the perl version. Note that this is the *only* benchmark where perl outperforms c++. That said, it's one data point and what you're doing may have totally different results. That's not to mention the effect of the compiler -- gcc doesn't have a greatest reputation for optimization although it's been improving. And, you're also depending on other programmers to write good benchmarks. Jeff