Michael Rasmussen wrote:
On Sat, May 26, 2012 at 05:52:19PM +0100, Rob Dixon wrote:
On 26/05/2012 14:07, pa...@fsmail.net wrote:
From: "Rob Dixon"<rob.di...@gmx.com>
On 26/05/2012 13:51, pa...@fsmail.net wrote:

  split is slower than the correct regex matching.

That is complete nonsense. Can you show a benchmark that supports your
claim?
I do know, and it is nonsense.

The benchmark below shows that split is better than twice as fast as a
regex for the application I have chosen.

If you can rewrite the program to show a diffferent use of regexes where
they are faster than an equivalent split then I will take it back.

Please stop deliberately spreading misinformation.
cmpthese(-5, {
   split =>  sub {
     my @array = split ' ', $str;
   },
   regex =>  sub {
     my @array = $str =~ /\S+/g;
   },
})

Curious, splitting on single char - what split has been optimized for, the awk 
behavior,
but the regex comparsion is splitting on non-whitespace,

The regular expression is not splitting!  It is capturing.

split removes whitespace.

The regular expression captures non-whitespace.

So the two expressions posted above are equivalent.


the inverse of what split is doing.
Correcting \S to \s returns similar results.

Did you actually examine the results produced?


But that raises the question of what happens when not splitting on the highly 
optimized space scenario.
First, let's see what happens when both split and the regex act on \S:
cmpthese(-5, {
   split =>  sub {
     my @array = split /\S+/, $str;

Remove non-whitespace and return whitespace.


   },
   regex =>  sub {
     my @array = $str =~ /\S+/g;

Capture and return non-whitespace.


   },
})



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to