$ perl -MO=Concise -e 'if ($x != -1 ){ print "foo" }' a <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 3 -e:1) v ->3 - <1> null vK/1 ->a 6 <|> and(other->7) vK/1 ->a 5 <2> ne sK/2 ->6 - <1> ex-rv2sv sK/1 ->4 3 <#> gvsv[*x] s ->4 4 <$> const[IV -1] s ->5 - <@> scope vK ->- - <0> ex-nextstate v ->7 9 <@> print vK ->a 7 <0> pushmark s ->8 8 <$> const[PV "foo"] s ->9 -e syntax OK $ perl -MO=Concise -e 'if ($x == 0 ){ print "foo" }' a <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 3 -e:1) v ->3 - <1> null vK/1 ->a 6 <|> and(other->7) vK/1 ->a 5 <2> eq sK/2 ->6 - <1> ex-rv2sv sK/1 ->4 3 <#> gvsv[*x] s ->4 4 <$> const[IV 0] s ->5 - <@> scope vK ->- - <0> ex-nextstate v ->7 9 <@> print vK ->a 7 <0> pushmark s ->8 8 <$> const[PV "foo"] s ->9 -e syntax OK
(Update) I guess at assembly level both boil down to a cmp (compare) followed either by an je (jump if equal) or jne (jump if not equal). I can't imagine a good reason why one of them should take longer.
It's one of those cases where you should really care more about readability than speed.
In reply to Re: Which is faster ?
by moritz
in thread Which is faster ?
by thenetfreaker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |