Skip to content

Instantly share code, notes, and snippets.

@samdark
Created January 21, 2013 09:17
Show Gist options
  • Select an option

  • Save samdark/4584804 to your computer and use it in GitHub Desktop.

Select an option

Save samdark/4584804 to your computer and use it in GitHub Desktop.
Memory usage of long and short variable names
<?php
class X
{
private $_b;
private $_e;
}
class Y
{
private $_behaviors;
private $_events;
}
$base = memory_get_usage();
echo "Start\n";
echo memory_get_usage() - $base."\n";
$a = new X();
$b = new X();
echo "X\n";
echo memory_get_usage() - $base."\n";
unset($a);
unset($b);
echo "Cleanup\n";
echo memory_get_usage() - $base."\n";
$a = new Y();
$b = new Y();
echo "Y\n";
echo memory_get_usage() - $base."\n";
unset($a);
unset($b);
echo "Cleanup\n";
echo memory_get_usage() - $base."\n";
@xeoncross

Copy link
Copy Markdown

You really need to create a number of objects of an order of magnitude to see the true difference. Two tiny classes aren't enough.

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