0

This test (CPU test from the Bitrix system), when launched on the server, directly yields more than 200. If you run it in Docker, then the test displays a value of about 10. Maybe someone has encountered such a problem?

<?php

echo GetPHPCPUMark();
function GetPHPCPUMark() {
        $res = array();
        $k = 0;
        for ($j = 0; $j < 4; $j++)
        {
            $s1 = getmicrotime();
            for ($i = 0; $i < 1000000; $i++)
            {
            }
            $e1 = getmicrotime();
            $N1 = $e1 - $s1;

            $s2 = getmicrotime();
            for ($i = 0; $i < 1000000; $i++)
            {
                //This is one op
                $k++;
                $k--;
                $k++;
                $k--;
            }
            $e2 = getmicrotime();
            $N2 = $e2 - $s2;

            if ($N2 > $N1)
                $res[] = 1 / ($N2 - $N1);
        }

        if (count($res))
            return array_sum($res) / doubleval(count($res));
        else
            return 0;   
}

function getmicrotime()
{
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
}
  • Microttime() is the wrong method on measuring performance in PHP. Use [hrtime()](https://www.php.net/manual/en/function.hrtime.php). – Markus Zeller Jun 23 '20 at 15:35
  • The question is how can I make existing code work faster. I cannot change the code itself ((( – user1907691 Jun 23 '20 at 18:48
  • Docker is a container. So you need to tune the hypervisor/virtualizer by maybe giving more resources. – Markus Zeller Jun 23 '20 at 18:58
  • I think so too, but I did not find these settings (( – user1907691 Jun 24 '20 at 14:33
  • What is the unit of that measurement? Also, how are server and docker set up? – Ulrich Eckhardt Jul 05 '20 at 06:08
  • @UlrichEckhardt unit of that measurement - digits from script in question. Server for tests: Ubuntu 18 with default settings (Docker also default settings, php7.4 - official docker image from docker hub). Measurement results differ on this server in docker and without it. – user1907691 Jul 06 '20 at 07:21

0 Answers0