Skip to content

Instantly share code, notes, and snippets.

@usagi
Created March 3, 2012 12:04
Show Gist options
  • Select an option

  • Save usagi/1965826 to your computer and use it in GitHub Desktop.

Select an option

Save usagi/1965826 to your computer and use it in GitHub Desktop.
PHP array size vs. memory usage
<?php
define ( 'K', 1024 );
define ( 'M', K * K );
define ( 'COUNT_MAX' , 10 * M );
define ( 'PRINT_STEP', 100 * K );
$memory_base = memory_get_usage();
$a = array();
for ( $n = 0; $n <= COUNT_MAX; ++$n ) {
if($n % PRINT_STEP === 0)
echo $n . "\t" . (memory_get_usage() - $memory_base) / M . "\n";
$a[$n] = $n;
}
?>
@usagi
Copy link
Copy Markdown
Author

usagi commented Mar 3, 2012

ideoneでもメモリリミッターの都合途中で止まるけどまあ傾向は見えます。
http://ideone.com/M5AQV

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment