Bug #79856 [Opn->Csd]: for() terribly poor performance
| From: | beberlei@php.net | Date: | Tue, 14 Jul 2020 07:40:56 +0000 |
| Subject: | Bug #79856 [Opn->Csd]: for() terribly poor performance | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-228025@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79856&edit=1
ID: 79856
Updated by: beberlei@php.net
Reported by: bugzilla77 at gmail dot com
Summary: for() terribly poor performance
-Status: Open
+Status: Closed
Type: Bug
Package: Performance problem
Operating System: Windows 10 Pro
PHP Version: 8.0.0alpha2
-Assigned To:
+Assigned To: beberlei
Block user comment: N
Private report: N
New Comment:
This is a bad comparison, because the result of the for loop can be calculated by the compiler in C#
or an advanced JIT in case of Javascript.
PHP has opcache optimizations, but I don't believe there is one for this for loop construct.
PHPs JIT is also in its infancy.
You should check instead calling a function that computes something inside the loop, for example a
string operation.
I don't consider this a bug, because of the benchmark assumptions being questionable, so
closing.
Previous Comments:
------------------------------------------------------------------------
[2020-07-14 07:36:17] bugzilla77 at gmail dot com
Description:
------------
for() terribly poor performance
Test script:
---------------
// --- php
<?php
$t=microtime(true);
$s=0;
for($i=0;$i<20000000;$i++){
$s+=$i;
}
$t=microtime(true)-$t;
print(($t*1000).'ms');
?>
// --- javascript
<script>
t=new Date();
s=0;
for(i=0;i<20000000;i++){
s+=i
}
t=new Date()-t;
document.write(t+'ms');
</script>
// --- C#
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
int t = Environment.TickCount;
long s = 0;
for (int i = 0; i < 20000000; i++)
{
s += i;
}
t = Environment.TickCount - t;
Console.WriteLine(t+"ms");
Console.ReadKey();
}
}
}
Expected result:
----------------
Performance at the level of other languages.
Actual result:
--------------
PHP 8.0alpha2: 343ms
PHP 7.4: 461ms
javascript (Firefox 78.0.2): 58ms
C#: 16ms
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79856&edit=1