Skip to content

Instantly share code, notes, and snippets.

Avatar

Aleksandr Zubarev zualex

View GitHub Profile
@zualex
zualex / array_vs_splfixedarray_memory_usage.php
Created Jun 8, 2021
Array vs SplFixedArray: memory usage
View array_vs_splfixedarray_memory_usage.php
<?php
$sizes = [];
for ($exp = 0; $exp < 18; $exp++) {
$size = pow(2, $exp);
if ($size < 1000) {
continue;
}
$sizes[] = $size - ($size / 4);
@zualex
zualex / array_vs_splfixedarray_memory_usage_simple.php
Last active Jun 8, 2021
Array vs SplFixedArray: memory usage simple
View array_vs_splfixedarray_memory_usage_simple.php
<?php
$sizes = [];
for ($exp = 0; $exp < 20; $exp++) {
$size = pow(2, $exp);
if ($size < 1000) {
continue;
}
$sizes[] = $size - ($size / 4);
@zualex
zualex / array_vs_splfixedarray_creation_time.php
Last active Jun 7, 2021
Array vs SplFixedArray: creation time
View array_vs_splfixedarray_creation_time.php
<?php
$sizes = [];
for ($exp = 0; $exp < 10; $exp++) {
$sizes[] = pow(2, $exp) * 1000;
}
echo "size, timeArray, timeSpl" . PHP_EOL;
foreach ($sizes as $size) {
View foreach_without_loop.php
<?php
function printMemory($start, $header) {
printf(
"%s - Time: %s | Memory (current): %s KB | Memory (max): %s KB" . PHP_EOL,
$header,
number_format(round((microtime(true) - $start) * 1000, 6), 6, ',', ''),
number_format(round((memory_get_usage() / 1024), 2), 2, ',', ''),
number_format(round((memory_get_peak_usage() / 1024), 2), 2, ',', '')
);
@zualex
zualex / array_replace_without_loop.php
Last active Mar 26, 2021
array_replace without loop
View array_replace_without_loop.php
<?php
function printMemory($start, $header) {
printf(
"%s - Time: %s | Memory (current): %s KB | Memory (max): %s KB" . PHP_EOL,
$header,
number_format(round((microtime(true) - $start) * 1000, 6), 6, ',', ''),
number_format(round((memory_get_usage() / 1024), 2), 2, ',', ''),
number_format(round((memory_get_peak_usage() / 1024), 2), 2, ',', '')
);
View plus_without_loop.php
<?php
function printMemory($start, $header) {
printf(
"%s - Time: %s | Memory (current): %s KB | Memory (max): %s KB" . PHP_EOL,
$header,
number_format(round((microtime(true) - $start) * 1000, 6), 6, ',', ''),
number_format(round((memory_get_usage() / 1024), 2), 2, ',', ''),
number_format(round((memory_get_peak_usage() / 1024), 2), 2, ',', '')
);
View spread_without_loop.php
<?php
function printMemory($start, $header) {
printf(
"%s - Time: %s | Memory (current): %s KB | Memory (max): %s KB" . PHP_EOL,
$header,
number_format(round((microtime(true) - $start) * 1000, 6), 6, ',', ''),
number_format(round((memory_get_usage() / 1024), 2), 2, ',', ''),
number_format(round((memory_get_peak_usage() / 1024), 2), 2, ',', '')
);
View array_merge_without_loop.php
<?php
function printMemory($start, $header) {
printf(
"%s - Time: %s | Memory (current): %s KB | Memory (max): %s KB" . PHP_EOL,
$header,
number_format(round((microtime(true) - $start) * 1000, 6), 6, ',', ''),
number_format(round((memory_get_usage() / 1024), 2), 2, ',', ''),
number_format(round((memory_get_peak_usage() / 1024), 2), 2, ',', '')
);
View foreach_in_loop.php
<?php
function printMemory($start, $header) {
printf(
"%s - Time: %s | Memory (current): %s KB | Memory (max): %s KB" . PHP_EOL,
$header,
number_format(round((microtime(true) - $start) * 1000, 6), 6, ',', ''),
number_format(round((memory_get_usage() / 1024), 2), 2, ',', ''),
number_format(round((memory_get_peak_usage() / 1024), 2), 2, ',', '')
);
View array_replace_in_loop.php
<?php
function printMemory($start, $header) {
printf(
"%s - Time: %s | Memory (current): %s KB | Memory (max): %s KB" . PHP_EOL,
$header,
number_format(round((microtime(true) - $start) * 1000, 6), 6, ',', ''),
number_format(round((memory_get_usage() / 1024), 2), 2, ',', ''),
number_format(round((memory_get_peak_usage() / 1024), 2), 2, ',', '')
);