in reply to perl process slower and slower when loop number increase

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

Replies are listed 'Best First'.
Re^2: perl process slower and slower when loop number increase
by Anonymous Monk on Jan 22, 2018 at 15:48 UTC
    ~$ uname -a Linux xxxxxxxxx 4.4.0-102-generic #125-Ubuntu SMP Tue Nov 21 15:13:42 +UTC 2017 i686 i686 i686 GNU/Linux $ perl -v This is perl 5, version 22, subversion 1 (v5.22.1) built for i686-linu +x-gnu-thread-multi-64int (with 60 registered patches, see perl -V for more detail) $ 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
Re^2: perl process slower and slower when loop number increase
by Anonymous Monk on Jan 22, 2018 at 16:09 UTC

    >> If I had to guess, with my terrible understanding of PHP, I'd wonder if the empty block was optimized away in PHP

    in first post I mention about "alioth benchmark game".

    see in

    perl vs php

    https://benchmarksgame.alioth.debian.org/u64q/compare.php?lang=perl&lang2=php

    or

    perl vs java

    https://benchmarksgame.alioth.debian.org/u64q/compare.php?lang=perl&lang2=php

    it's maybe just "toy" or "game", but look at 1 example 'n-body' test, perl and php have similiar logic, and what make perl slow I thing the test need 50_000_000 loop and more loop in body of the test

      Ok lets step back a bit. why are you surprised that php does better than perl in some benchmarks?

      Dave.

        no, it's not about PHP or perl vs XXXX

        it's about how to make perl loop faster, and back to first post,I think there is "magic setting" to increase this limitation

        see image provide by choroba above