php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #64894 information about speed
Submitted: 2013-05-22 02:51 UTC Modified: 2013-05-22 05:01 UTC
From: roberto at spadim dot com dot br Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.4.15 OS: linux
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: roberto at spadim dot com dot br
New email:
PHP Version: OS:

 

 [2013-05-22 02:51 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-05-22 04:44 UTC] sixd@php.net
Please use an appropriate mail list to ask questions:
http://php.net/mailing-lists.php
 [2013-05-22 04:44 UTC] sixd@php.net
-Status: Open +Status: Not a bug
 [2013-05-22 05:01 UTC] roberto at spadim dot com dot br
there's a benchmark list?
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat May 03 10:01:27 2025 UTC