Beefy Boxes and Bandwidth Generously Provided by pair Networks
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??


in reply to Function speeds: lc() vs. eq vs. =~

use Benchmark.

I did a benchmark and came up with the following:

Benchmark: timing 1000000 iterations of eq, lc, re... eq: 3 wallclock secs ( 2.76 usr + 0.00 sys = 2.76 CPU) lc: 3 wallclock secs ( 2.69 usr + 0.00 sys = 2.69 CPU) re: 3 wallclock secs ( 3.13 usr + 0.00 sys = 3.13 CPU)
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://72892]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-20 03:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found