Use Benchmark when in doubt. YMMV. The first thing I would do for speeding that up is adding a + after the character class, but below proves I'm wrong.
$ cat test.pl #!/pro/bin/perl use strict; use warnings; use Benchmark "cmpthese"; my $string = pack "A*" => map { chr (32 + int rand 95) } 0..1280; cmpthese (-1, { subsingle => '(my $s = $string) =~ s/[^a-zA-Z0-9 _-]//g', subplus => '(my $s = $string) =~ s/[^a-zA-Z0-9 _-]+//g', tran => '(my $s = $string) =~ tr/a-zA-Z0-9 _-//cd', }); $ perl5.8.8 test.pl Rate tran subplus subsingle tran 5938537/s -- -1% -2% subplus 5983722/s 1% -- -1% subsingle 6052802/s 2% 1% -- $ perl5.10.1 test.pl Rate tran subplus subsingle tran 5242880/s -- -2% -5% subplus 5344683/s 2% -- -3% subsingle 5531478/s 6% 3% -- $ perl5.12.3 test.pl Rate tran subplus subsingle tran 5044286/s -- -2% -4% subplus 5144881/s 2% -- -2% subsingle 5242880/s 4% 2% -- $ perl5.14.1 test.pl Rate tran subplus subsingle tran 5144881/s -- -9% -10% subplus 5663605/s 10% -- -1% subsingle 5716536/s 11% 1% -- $
In reply to Re^2: Remove all non alphanumeric characters excluding space, underscore and minus sign
by Tux
in thread Remove all non alphanumeric characters excluding space, underscore and minus sign
by ikkeniet
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |