php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45247 45 times slower execution of PHP code snipet than with asp.net
Submitted: 2008-06-12 13:02 UTC Modified: 2008-06-12 13:25 UTC
From: itay dot malimovka at gmail dot com Assigned:
Status: Not a bug Package: Performance problem
PHP Version: 5.2.6 OS: Linux and Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: itay dot malimovka at gmail dot com
New email:
PHP Version: OS:

 

 [2008-06-12 13:02 UTC] itay dot malimovka at gmail dot com
Description:
------------
the following code is run ~45 times slower compared to a similar C# code.
I run the test on several machines (32 & 64, Windows and Linux-on linux only the PHP).

Notice in the example below I give both PHP and C# codes I used.

Reproduce code:
---------------
//PHP
//----------------------------------------------------------------------------------------------------------------
<?php
set_time_limit(0);
$start=time();
$arr = array(1,2,3,4,5,6,7,8,9,0);
$x = 8;
for ($i=0;$i<94707441;$i++)
{
$x = $arr[$i%10];
$y = $arr[$i%7];
if ($x == $y)
{
$total += $x*$y;
//$words .= ','.$x;
}
}
echo $total."<Br>";

echo "total time : ".(time()-$start);

?>
//C#
//----------------------------------------------------------------------------------------------------------------
int startTime = Environment.TickCount;
int[] arr;
arr = new int[10] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };


int x = 8;
int y=0;
int total=0;
for (int i = 0; i < 94707441; i++)
{
x = arr[i%10];
y = arr[i%7];
if(x == y)
total+=x*y;

}
Response.Write(total+"<br>");
int endTime = Environment.TickCount;
double executionTime = (double)(endTime - startTime) / 1000.0;

Response.Write("Page Execution time is " + executionTime + " seconds.");

Expected result:
----------------
at least execution time should be the same.

Actual result:
--------------
php runs much much slower X45 that asp.net

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-06-12 13:25 UTC] mgf@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Order-of-magnitude differences in execution times are ro be expected when comparing a compiled language with an interpreted one.  Try comparing PHP with other interpreted languages such as perl, Ruby, Python, etc.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 14:01:29 2024 UTC