<?php
$ar1 = [];
$memNow1 = memory_get_usage();
$tm1 = microtime(true);
for ($i1 = 0; $i1 < 25000; $i1++) {
$ar1[] = [
'a' => 1,
'b' => 2,
'c' => 3,
'd' => 4,
];
}
echo 'Arrays memory usage: ', (memory_get_usage() - $memNow1) / 1048576, '; time: ', microtime(true) - $tm1, PHP_EOL;
class C {
public $a, $b, $c, $d;
}
$ar2 = [];
$memNow2 = memory_get_usage();
$tm2 = microtime(true);
for ($i2 = 0; $i2 < 25000; $i2++) {
$o = new C();
$o->a = 1;
$o->b = 2;
$o->c = 3;
$o->d = 4;
$ar2[] = $o;
}
echo 'Objects memory usage: ', (memory_get_usage() - $memNow2) / 1048576, '; time: ', microtime(true) - $tm2, PHP_EOL;
preferences:
27.54 ms | 405 KiB | 5 Q