peachpiecompiler / peachpie

PeachPie - the PHP compiler and runtime for .NET and .NET Core
https://www.peachpie.io
Apache License 2.0
2.33k stars 202 forks source link

Hello!Why do compiled executables run slower than PHP script interpretation #996

Closed avriltank closed 2 years ago

avriltank commented 2 years ago
<?php

function main()
{
    $start = microtime(true);
    $sum = 0;
    for ($i = 0; $i < 10000000000; $i++) {
            $sum += $i;
    }
    $end = microtime(true);
    echo $end - $start;
}

main();

php81-jit:28s peachpie-exe:142s

I think pechpie also run as a script!

jakubmisek commented 2 years ago

There is not enough information; please specify what's the command line arguments, and ensure you're not debugging the script from Visual Studio.

Also, please note, PHP nor PeachPie do not run as a script (whatever it means).

jakubmisek commented 2 years ago

just checked; PeachPie 1.0 produces the following equivalent to the compiled C# program:

public static void main(Context? <ctx>) {
    PhpNumber sum = PhpNumber.Default;
    PhpValue start = Miscellaneous.microtime(returnDouble: true);
    sum = 0L;
    for (long i = 0L; i < 10000000000L; i++) {
        sum += i;
    }
    PhpValue end = Miscellaneous.microtime(returnDouble: true);
    Operators.Echo(PhpNumber.Sub(end, start), <ctx>);
}

which is the best we can do; please share your project and steps to reproduce the benchmark.

avriltank commented 2 years ago

First,thanks for your reply!This is great project!As a general rule, the compiled code's speed should not be so slow!But the result takes 142s!The same php code run in php8-jit only takes 25s