<?php echo 'With class: '; $start_time = microtime(TRUE); class Data { public $foo = 'example'; public $bar = 'example'; } $data = new Data(); for ($i = 0; $i < 10000; $i++) { $prop = 'foo'; $data->$prop; // access property but no echo, just to not polute the output; } $end_time = microtime(TRUE); echo $end_time - $start_time . "\n"; echo "With array: "; $start_time = microtime(TRUE); $data = [ 'foo' => 'example', 'bar' => 'example', ]; for ($i = 0; $i < 10000; $i++) { $prop = 'foo'; $data[$prop]; // access key but no echo, just to not polute the output; } $end_time = microtime(TRUE); echo $end_time - $start_time . "\n"; echo "With converted stdClass: "; $start_time = microtime(TRUE); $data = (object) [ 'foo' => 'example', 'bar' => 'example', ]; for ($i = 0; $i < 10000; $i++) { $prop = 'foo'; $data->$prop; // access propery but no echo, just to not polute the output; } $end_time = microtime(TRUE); echo $end_time - $start_time;
You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).