use strict; use warnings; use Time::HiRes 'time'; my $doc = "'C-3PO' or 'See-Threepio' is a humanoid robot character from the [[Star Wars]] universe who appears in the original ''Star Wars'' films, the prequel trilogy and the sequel trilogy.\n"; $doc .= $doc for 1 .. 22; ## expand string to 724 MB print "length : ", length($doc), "\n"; # 759169024 my $start = time; # $doc =~ s/\[\[//g; ## 8.626 secs. # $doc =~ s/\]\]//g; # $doc =~ s/\'//g; # $doc =~ s/\[//g; ## 10.493 secs. # $doc =~ s/\]//g; # $doc =~ s/\'//g; # $doc =~ s/\[+//g; ## 7.050 secs. # $doc =~ s/\]+//g; # $doc =~ s/\'+//g; # $doc =~ s/(?:\[|\]|\')//g; ## 19.559 secs. # $doc =~ s/(?:\[|\]|\')+//g; ## 56.150 secs. <- did not expect this # $doc =~ s/[\[\]\']//g; ## 9.072 secs. # $doc =~ s/[\[\]\']+//g; ## 6.915 secs. $doc =~ tr/[]'//d; ## 1.908 secs. printf "duration : %7.03f secs.\n", time - $start; print "length : ", length($doc), "\n"; # 708837376