Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re: Re+ :Perl Idioms Explained: && and || "Short Circuit" operatorsby demerphq (Chancellor) |
on Oct 23, 2003 at 12:25 UTC ( [id://301554]=note: print w/replies, xml ) | Need Help?? |
So the rub of this is that switch() is not O(1). But that as often as possible the optimizer will do its best to convert it to be so. Which if you think about it means that from a programmers perspective its merely syntactic sugar for a chain of ifs. I say this becuase its just as reasonable to assume that the optimizer could figure out that a chain of ifs can be represented by a jump table and do the same optimization there. Also in your private message to me you mentioned that on occassion the compiler constructs a multi gigabyte executable to try to provide this "optimization". Which I would have thought _totally_ defeats the purpose given that the swap/thrash times involved to implement it would _far_ outweigh the execution times of a chained if. Anyway, many thanks to you and the other respondants about this. I have certainly learned something.
---
demerphq First they ignore you, then they laugh at you, then they fight you, then you win.
In Section
Meditations
|
|