in reply to Re: Comparing Regular Expressions
in thread Comparing Regular Expressions

Your benchmark is bogus.

Realize that s/// actually modifies the string it's operating on. After the first iteration, there will be no spaces around commas left in $text.

Furthermore, you assign to $TestText, but you never actually use its value.

Replies are listed 'Best First'.
Re^3: Comparing Regular Expressions
by Sewi (Friar) on Sep 01, 2009 at 07:13 UTC
    You're completly right. Thank you for the hints.

    perl -le '$text = <STDIN>; $T=time; for (1..$ARGV[0]) { my $TestText = + $text; $TestText =~ s/\s+,\s+|\s+,|,\s+/,/g; } print time - $T; $T=t +ime; $TestText=$text; for (1..$ARGV[0]) { my $TestText = $text; $Test +Text =~ s/\s*,\s*/,/g; } print time - $T;' 1000000 </tmp/text.file
    This should correct all bugs.