PHP code example of monoless / arrays

1. Go to this page and download the library: Download monoless/arrays library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

monoless / arrays example snippets



define('ARRAY_LENGTH', 10000);
$start_memory = memory_get_usage();

$entries = new \Monoless\Arrays\FixedUnsignedIntegerArray(ARRAY_LENGTH);
for ($i = 0; $i < ARRAY_LENGTH; $i++) {
    $entries[$i] = mt_rand(0, 255);
}

$memory = memory_get_usage() - $start_memory;
echo "fixed unsigned integer array memory usage : {$memory}\n";

$start = microtime(true);

$result = 0;
for ($i = 0; $i < ARRAY_LENGTH; $i++) {
    $result += $entries[$i];
}

$time_elapsed_secs = microtime(true) - $start;
echo "for iterator fixed unsigned integer array : {$time_elapsed_secs}\n";

// legacy array
$start_memory = memory_get_usage();

$rands = [];
for ($i = 0; $i < ARRAY_LENGTH; $i++) {
    $rands[] = mt_rand(0, 255);
}

$memory = memory_get_usage() - $start_memory;
echo "legacy array memory usage : {$memory}\n";

$start = microtime(true);

$result = 0;
for ($i = 0; $i < ARRAY_LENGTH; $i++) {
    $result += $rands[$i];
}

$time_elapsed_secs = microtime(true) - $start;
echo "for iterator legacy array : {$time_elapsed_secs}\n";