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?

There are many cases prove that, I am just lazy to find one.
You don't know it, so it's nonsense?

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.

Rob


use strict;
use warnings;

use Benchmark 'cmpthese';
use List::Util 'shuffle';

my $str;

for my $i (1 .. 101) {
  if ($i & 1) {
    $str .= join '', (shuffle 'A' .. 'Z')[0..rand 10];
  }
  else {
    $str .= ' ' x (rand 10 + 1);
  }
}

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

__END__

**OUTPUT**

         Rate regex split
regex 16744/s    --  -55%
split 37360/s  123%    --

Tool completed successfully

--
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