Sébastien Aperghis-Tramoni wrote: > Q: Why do you use /[Tt]/ instead of /t/i? It's so ugly! > > A: Simple - the case-insensitive match switch is very > inefficient. According to "Mastering Regular Expressions" > from O'Reilly Press, /[Tt]/ is faster and more space > efficient than /t/i - by as much as double against long > strings. //i essentially does a lc() on the string and > keeps a temporary copy in memory. > > When this changes, and it is in the 5.6 development series, > I will gladly use //i. Believe me, I realize [Tt] is hideously > ugly.
Looks like it was painfully true for 5.5... $ time perl5.5.5 -wle '$foo = "x" x 10000; $foo .= "T"; $foo =~ /[Tt]/ for 1..100000' real 0m4.882s user 0m4.761s sys 0m0.026s $ time perl5.5.5 -wle '$foo = "x" x 10000; $foo .= "T"; $foo =~ /t/i for 1..100000' real 0m40.656s user 0m39.587s sys 0m0.149s And the reverse is now true in this highly inaccurate test... $ time perl5.8.8 -wle '$foo = "x" x 10000; $foo .= "T"; $foo =~ /[Tt]/ for 1..100000' real 0m5.732s user 0m5.565s sys 0m0.027s $ time perl5.8.8 -wle '$foo = "x" x 10000; $foo .= "T"; $foo =~ /t/i for 1..100000' real 0m2.589s user 0m2.544s sys 0m0.015s -- <Schwern> What we learned was if you get confused, grab someone and swing them around a few times -- Life's lessons from square dancing