38
loading...
This website collects cookies to deliver better user experience
$array_numeric=[$hello,$second,$third];
$array_not_numeric=['hello'=>$hello,'second'=>$second,'third'=>$third];
$object_constructor=DummyClass('world',0,20.3);
$object_no_constructor=new DummyClass2();
$object_no_constructor->hello='world';
$object_no_constructor->second=0;
$object_no_constructor->third=20.3;
array numeric no factory | array no factory | array numeric factory | array factory | object constructor | object no constructor | object no constructor setter/getter | object no constructor setter/getter (magic) | object no constructor stdClass |
---|---|---|---|---|---|---|---|---|
0.038275957107543945 | 0.04024696350097656 | 0.12892484664916992 | 0.15126800537109375 | 0.12696218490600586 | 0.08770990371704102 | 0.21163702011108398 | 0.3990211486816406 | 0.13244986534118652 |
array numeric no factory | array no factory | array numeric factory | array factory | object constructor | object no constructor | object no constructor setter/getter | object no constructor setter/getter (magic) | object no constructor stdClass |
---|---|---|---|---|---|---|---|---|
0% | 5.15% | 236.83% | 295.2% | 231.7% | 129.15% | 452.92% | 942.49% | 246.04% |
$customer[0]='john'; // faster but it is hard to understand
$customer['name']='john'; // almost as fast as the first one but it is clear to understand (it also uses more memory)
$customer->name='john'; // (where $customer is an object of the class Customer) slower but it still acceptable.
$customer->name='john'; // (where $customer is an object of the class stdClass) the double of slower than to use a class.
$customer=new Customer('john'); // (constructor) even slower but is still acceptable;
$customer=factory('john'); // (where factory is an array that returns an array). Slower than the use of constructor.
$customer->setName('john'); // bad performance
$customer->name='john'; // (where the class uses a magic method) awful performance, avoid this one.