From: roberto at spadim dot com dot br
Operating system: linux
PHP version: 5.4.15
Package: *General Issues
Bug Type: Feature/Change Request
Bug description:information about speed
Description:
------------
hi guys, could anyone explain this results?
why a $array['string'] is slower to "++" operator and $array[0] and
$class-
>variable and $single_var
and why a $var that point to anyone of this type of var
$point=&$to_this_var; is
faster than anyone?
Test script:
---------------
<?php
class a{
var $t;
}
$array=array(0=>0,'t'=>0);
$var=0;
$class=new a;
$qnt=10000000;
$t1=microtime(1);
for($i=0;$i<$qnt;$i++)
$array['t']++;
$t2=microtime(1);
for($i=0;$i<$qnt;$i++)
$array[0]++;
$t3=microtime(1);
for($i=0;$i<$qnt;$i++)
$class->t++;
$t4=microtime(1);
for($i=0;$i<$qnt;$i++)
$var++;
$t5=microtime(1);
echo "array with string index: ".($t2-$t1)."\n".
"array with number index: ".($t3-$t2)."\n".
"class public var: ".($t4-$t3)."\n".
"var: ".($t5-$t4)."\n".
'';
$array=array(0=>0,'t'=>0);
$var=0;
$class=new a;
$qnt=10000000;
$v1=&$array['t'];
$v2=&$array[0];
$v3=&$a->t;
$v4=&$var;
$t1=microtime(1);
for($i=0;$i<$qnt;$i++)
$v1++;
$t2=microtime(1);
for($i=0;$i<$qnt;$i++)
$v2++;
$t3=microtime(1);
for($i=0;$i<$qnt;$i++)
$v3++;
$t4=microtime(1);
for($i=0;$i<$qnt;$i++)
$v4++;
$t5=microtime(1);
echo "& array with string index: ".($t2-$t1)."\n".
"& array with number index: ".($t3-$t2)."\n".
"& class public var: ".($t4-$t3)."\n".
"& var: ".($t5-$t4)."\n".
'';
Expected result:
----------------
array with string index: 0.80007791519165 (at least sabe time as
$array[0])
array with number index: 0.65114402770996 (why not faster like $var?)
class public var: 0.5907871723175 (why not faster like $var?)
var: 0.47185897827148 (why not faster like & $var?)
& array with string index: 0.46768593788147 (why faster than a
$var?!?!?!?!)
& array with number index: 0.46670913696289
& class public var: 0.46836400032043
& var: 0.46757102012634
Actual result:
--------------
array with string index: 0.80007791519165
array with number index: 0.65114402770996
class public var: 0.5907871723175
var: 0.47185897827148
& array with string index: 0.46768593788147
& array with number index: 0.46670913696289
& class public var: 0.46836400032043
& var: 0.46757102012634
system is only running me, it's linux with php, nothing less, nothing more
downloaded slackware and php
--
Edit bug report at https://bugs.php.net/bug.php?id=64894&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=64894&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=64894&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=64894&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=64894&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=64894&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=64894&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=64894&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=64894&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=64894&r=support
Expected behavior: https://bugs.php.net/fix.php?id=64894&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=64894&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=64894&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=64894&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64894&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=64894&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=64894&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=64894&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=64894&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=64894&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=64894&r=mysqlcfg