I cannot reproduce results so dramatic as yours. While Perl does come out slower in this test, it is not over four times slower, as your example is producing:

$ time perl -e 'for ($x=0; $x!=100_000_000; ++$x) {}' real 0m2.448s user 0m2.446s sys 0m0.002s $ time php -r 'for($x=0; $x!=100000000; ++$x){};' real 0m1.570s user 0m1.562s sys 0m0.008s

Looking at the output of B::Concise does not reveal any smoking gun in the case of the Perl code (I don't know how to deparse PHP similarly). It would be interesting to see the output of the following command on your system that is producing a 4.5x performance penalty for Perl:

$ perl -MO=Concise -e 'for ($x=0; $x!=100_000_000; ++$x) {}' h <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v:{ ->3 5 <2> sassign vKS/2 ->6 3 <$> const(IV 0) s ->4 - <1> ex-rv2sv sKRM*/1 ->5 4 <$> gvsv(*x) s ->5 6 <0> unstack v* ->7 g <2> leaveloop vK/2 ->h 7 <{> enterloop(next->9 last->g redo->8) v ->c - <1> null vK/1 ->g f <|> and(other->8) vK/1 ->g e <2> ne sK/2 ->f - <1> ex-rv2sv sK/1 ->d c <$> gvsv(*x) s ->d d <$> const(IV 100000000) s ->e - <@> lineseq vK ->- - <@> scope vK ->9 8 <0> stub v ->9 a <1> preinc vK/1 ->b - <1> ex-rv2sv sKRM/1 ->a 9 <$> gvsv(*x) s ->a b <0> unstack v ->c -e syntax OK

If I had to guess, with my terrible understanding of PHP, I'd wonder if the empty block was optimized away in PHP, eliminating the repeated creation and tear-down of a scope. But at minimum it might be revealing to see what your version of Perl is doing inside the loop.


Dave


In reply to Re: perl process slower and slower when loop number increase by davido
in thread perl process slower and slower when loop number increase by Anonymous Monk

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.