Keep It Simple, Stupid | |
PerlMonks |
Re: Function speeds: lc() vs. eq vs. =~by btrott (Parson) |
on Apr 16, 2001 at 22:12 UTC ( [id://72892]=note: print w/replies, xml ) | Need Help?? |
use Benchmark. I did a benchmark and came up with the following: lc is your first code snippet, eq the second, and re the third. You *really* don't need to worry about the differences in speed, unless you're doing this 100000 times or something like that. Seriously: don't try to optimize things like this. Testing case-insensitive equality is *such* a fast operation that you shouldn't be worrying about it--yes, even in an interactive situation. Instead worry about Getting It Right. For example, what does your second code snippet do if $type is 'Cr' or 'cR'? Maybe you don't think you need to worry about those things, but I say you should: it's definitely more important than worrying about a couple of milliseconds per every 100000 case-insensitive equality checks.
In Section
Seekers of Perl Wisdom
|
|