Skip to content

Instantly share code, notes, and snippets.

View zualex's full-sized avatar

Aleksandr Zubarev zualex

View GitHub Profile
@zualex
zualex / array_vs_splfixedarray_memory_usage.php
Created June 8, 2021 10:19
Array vs SplFixedArray: memory usage
<?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 June 8, 2021 10:19
Array vs SplFixedArray: memory usage simple
<?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 June 7, 2021 10:09
Array vs SplFixedArray: creation time
<?php
$sizes = [];
for ($exp = 0; $exp < 10; $exp++) {
$sizes[] = pow(2, $exp) * 1000;
}
echo "size, timeArray, timeSpl" . PHP_EOL;
foreach ($sizes as $size) {
@zualex
zualex / foreach_without_loop.php
Created March 26, 2021 07:58
foreach without loop
<?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 March 26, 2021 07:59
array_replace without loop
<?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 / plus_without_loop.php
Last active March 26, 2021 07:59
+ without loop
<?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 / spread_without_loop.php
Created March 26, 2021 07:56
... without loop
<?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_merge_without_loop.php
Created March 26, 2021 07:55
array_merge without loop
<?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 / foreach_in_loop.php
Created March 26, 2021 07:54
foreach in loop
<?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_in_loop.php
Created March 26, 2021 07:54
array_replace in loop
<?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, ',', '')
);