А я тут потестировал немного.
<?php
$test_iteration = 50000000;
function get_rand_data() {
return [
'a' => mt_rand(1, 1000),
'b' => mt_rand(1, 1000),
'c' => mt_rand(1, 1000),
'd' => mt_rand(1, 1000),
'e' => mt_rand(1, 1000),
];
}
function prepare_data(&$data) {
return ($data['a'] * $data['b'] / ( $data['c'] * $data['d'] )) / $data['e'];
}
class Data {
protected $data = [];
public function __construct(array &$data = []) {
$this->data = $data;
}
public function run() {
return ($this->data['a'] * $this->data['b'] / ( $this->data['c'] * $this->data['d'] )) / $this->data['e'];
}
public function setData(array &$data) {
$this->data = $data;
return $this;
}
public function setDataNotReturn(array &$data) {
$this->data = $data;
}
}
class StaticData {
public static function run(&$data) {
return ($data['a'] * $data['b'] / ( $data['c'] * $data['d'] )) / $data['e'];
}
}
function show_delta($end, $start, $text) {
return $text.': '.round(($end-$start), 5). " seconds\n";
}
$start = microtime(1);
for($i =0; $i<$test_iteration; ++$i) {
$data = get_rand_data();
prepare_data($data);
}
echo show_delta(microtime(1), $start, 'Array mode');
$start = microtime(1);
for($i =0; $i<$test_iteration; ++$i) {
$data = get_rand_data();
$result = ($data['a'] * $data['b'] / ( $data['c'] * $data['d'] )) / $data['e'];
}
echo show_delta(microtime(1), $start, 'Array run body for mode');
$start = microtime(1);
for($i =0; $i<$test_iteration; ++$i) {
$data = get_rand_data();
(new Data($data))->run();
}
echo show_delta(microtime(1), $start, 'Object mode');
$start = microtime(1);
$runner = new Data();
for($i =0; $i<$test_iteration; ++$i) {
$data = get_rand_data();
$runner->setData($data)->run();
}
echo show_delta(microtime(1), $start, 'Object mode (v2)');
$start = microtime(1);
$runner = new Data();
for($i =0; $i<$test_iteration; ++$i) {
$data = get_rand_data();
$runner->setDataNotReturn($data);
$runner->run();
}
echo show_delta(microtime(1), $start, 'Object mode (v3)');
$start = microtime(1);
for($i =0; $i<$test_iteration; ++$i) {
$data = get_rand_data();
StaticData::run($data);
}
$delta = microtime(1) - $start;
echo show_delta(microtime(1), $start, 'Static object mode');
user@local:~$ php /tmp/test.php
Array mode: 146.38443 seconds
Array run body for mode: 170.97489 seconds
Object mode: 232.68619 seconds
Object mode (v2): 200.46042 seconds
Object mode (v3): 191.89959 seconds
Static object mode: 146.72426 seconds
у меня вот так получилось...
выходит, статический метод объекта практически идентичен массиву с функцией обработки...