mirror of
https://github.com/codeguy/php-the-right-way.git
synced 2025-08-08 06:56:33 +02:00
Tweak perf example in The Basics
This commit is contained in:
@@ -307,16 +307,16 @@ echo ($a == 5) ? return true : return false; // this example will output an e
|
||||
|
||||
At times, coders attempt to make their code "cleaner" by declaring predefined variables with a different name. What
|
||||
this does in reality is to double the memory consumption of said script. For the example below, let's say
|
||||
$_GET\['about_me'\] contains 1MB worth of data, by copying the variable you've increased the scripts execution to 2MB.
|
||||
an example string of text contains 1MB worth of data, by copying the variable you've increased the scripts execution to 2MB.
|
||||
|
||||
{% highlight php %}
|
||||
<?php
|
||||
$about = $_GET['about_me']; // uses 2MB memory
|
||||
$about = 'A very long string of text'; // uses 2MB memory
|
||||
echo $about;
|
||||
|
||||
vs.
|
||||
|
||||
echo $_GET['about_me']; // uses 1MB memory
|
||||
echo 'A very long string of text'; // uses 1MB memory
|
||||
{% endhighlight %}
|
||||
|
||||
* [Performace tips](https://developers.google.com/speed/articles/optimizing-php)
|
Reference in New Issue
Block a user