It seems to produce roughly the same optree, with the same number of opcodes, so there should be no speed difference at all. Try to Benchmark it, if you can't write a benchmark that shows a speed difference it's not worth worrying about.
$ 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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.