in reply to Which is faster ?

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.

Replies are listed 'Best First'.
Re^2: Which is faster ?
by thenetfreaker (Friar) on Jun 04, 2008 at 12:52 UTC
    I just thought it checks/compares more signs in the case of $flag ne -1
    and thaks a lot for the clearyfing and I'll do the Benchmark.
    Btw, what does "-MO=Concise" exactlly do ?
      I just thought it checks/compares more signs in the case of $flag ne -1

      $flag != -1 and $flag ne -1 aren't the same thing. ne is string comparison, and I could well imagine that it's slightly slower (but I really doubt that I'm able to prove that in a benchmark, so don't believe me).

      Btw, what does "-MO=Concise" exactlly do ?

      It's the same as use B::Concise;, which prints something like a syntax tree for the program. See B::Concise for more information.

        I asked about "-MO=Concise" because its output reminded of Assembly
        so i wandered if there's a way to convert a perl script into an .asm file ?
        I need it because I'm working on a program that evantually I want to "convert" into a microchip,
        therefore, I need an asm prototype of my program for some machines in an electronic facility
        in my town to make a chip out of my "algorythm".
        So is there a way to convert perl to asm ?