in reply to Re^3: performance enhancement
in thread performance enhancement
Why s/^\s+|\s*$/g rather than s/^\s+|\s+$/g, s/^\s*|\s*$/g or s/^\s*|\s+$/g?
Er, the quantifier mismatch was a typo. I have corrected the original node.
But its good as you can see the speed advantage of the twosub method. Although I suspect you would see a radically different result if the string were more "normal" for instance the content of a node, with the intention of triming each line.
Also you have to be very careful with benchmarking regexes, really subtle differences in the input string and the pattern can result in wildly different run times due to how the optimiser handles them. For instance if your string/pattern facilitates a single FBM search followed by a match followed by a failing FBM search then its going to be massivley faster than a pattern where a FBM search matches many times, each rejected by the regex engine itself afterwards. FBM is really fast, the regex engine is not. In fact despite the common perception that the regex engine itself is fast Id say its not, rather the reputation comes from using a lot of really tricky optimisations to cut down as much as possible how much the regex engine proper is involved. In other words the perl regex engine is perceived as fast mostly because we do our damndest not to use it when we dont need to.
|
|---|