in reply to Re: Re: Idiomatic optimizations
in thread Idiomatic optimizations
On an otherwise unloaded P4 1.g GHz
For certain very specific meanings of the word "unloaded", I'm sure. "foo" is optimized to 'foo' at compile time, so neither of them can possibly be faster. As you can see, the generated bytecode is equivalent:
Even "Hello, $name!" is optimized to 'Hello, ' . $name . '!'.2;0 juerd@ouranos:~$ perl -MO=Concise -e'$foo = "foo"' 6 <@> leave[t1] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v ->3 5 <2> sassign vKS/2 ->6 3 <$> const(PV "foo") s ->4 - <1> ex-rv2sv sKRM*/1 ->5 4 <$> gvsv(*foo) s ->5 -e syntax OK 2;0 juerd@ouranos:~$ perl -MO=Concise -e'$foo = '\''bar'\' 6 <@> leave[t1] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v ->3 5 <2> sassign vKS/2 ->6 3 <$> const(PV "bar") s ->4 - <1> ex-rv2sv sKRM*/1 ->5 4 <$> gvsv(*foo) s ->5 -e syntax OK
Note: I _do_ think people should use single quotes when not interpolating. It saves you a lot of hits on the backslash key, and avoids getting bitten by: "$You're kidding me" (eq. "$You::re kidding me"), "my@emailaddress.com" (intended: "my\@emailaddress.com").
- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: Re: Idiomatic optimizations
by belg4mit (Prior) on May 01, 2002 at 17:00 UTC | |
by Juerd (Abbot) on May 01, 2002 at 19:05 UTC | |
by belg4mit (Prior) on May 01, 2002 at 20:50 UTC | |
by Juerd (Abbot) on May 01, 2002 at 21:03 UTC | |
by belg4mit (Prior) on May 01, 2002 at 21:13 UTC |
In Section
Meditations