performance - Perl: why is the if statement slower than "and"? -
in perl, conditional can expressed either as
if (condition) { }
or as
(condition) , { }
interestingly, second way seems 10% faster. know why?
some comments deparse below:
first, don't use b::terse, it's obsolete. b::concise gives better information once used it.
second, you've run using literal code given, condition taken bareword happens true, boolean check optimized away in both cases, kind of defeats purpose.
third, there isn't opcode - "null" indicates opcode that's been optimized away (completely out of execution tree, though still in parse tree.)
here's concise execution tree 2 cases, shows them identical:
$ perl -mo=concise,-exec -e'($condition) , { }' 1 <0> enter 2 <;> nextstate(main 2 -e:1) v 3 <#> gvsv[*condition] s 4 <|> and(other->5) vk/1 5 <$> const[pv "something"] s/bare 6 <1> dofile vk/1 7 <@> leave[1 ref] vkp/refc -e syntax ok $ perl -mo=concise,-exec -e'if ($condition) { }' 1 <0> enter 2 <;> nextstate(main 3 -e:1) v 3 <#> gvsv[*condition] s 4 <|> and(other->5) vk/1 5 <$> const[pv "something"] s/bare 6 <1> dofile vk/1 7 <@> leave[1 ref] vkp/refc -e syntax ok
Comments
Post a Comment