Edit report at https://bugs.php.net/bug.php?id=64894&edit=1

 ID:                 64894
 User updated by:    roberto at spadim dot com dot br
 Reported by:        roberto at spadim dot com dot br
 Summary:            information about speed
 Status:             Not a bug
 Type:               Feature/Change Request
 Package:            *General Issues
 Operating System:   linux
 PHP Version:        5.4.15
 Block user comment: N
 Private report:     N

 New Comment:

there's a benchmark list?


Previous Comments:
------------------------------------------------------------------------
[2013-05-22 04:44:42] s...@php.net

Please use an appropriate mail list to ask questions:
http://php.net/mailing-lists.php

------------------------------------------------------------------------
[2013-05-22 02:51:08] roberto at spadim dot com dot br

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 this bug report at https://bugs.php.net/bug.php?id=64894&edit=1

Reply via email to