Ec (2); helps code optimization by detecting memory usage of scripts. PHP provides a garbage collector and a very complex memory manager. The amount of memory used for script execution is increased or decreased. To get the current memory usage, we can use the memory_get_usage () function. To obtain the maximum memory usage at any time point, you can use the memory_limit () function. Viewsourceprint? 01 echo & quot; I script ec (2); script
By detecting the memory usage of the script, the code is optimized. PHP provides a garbage collector and a very complex memory manager. The amount of memory used for script execution is increased or decreased. To get the current memory usage, we can use the memory_get_usage () function. To obtain the maximum memory usage at any time point, you can use the memory_limit () function. View sourceprint? 01 echo "Initial:
| The Code is as follows: |
|
|
". Memory_get_usage ()." bytes ";
02/* prints
03 Initial: 361400 bytes
04 */
05
06 // let's use up some memory
07 for ($ I = 0; I I <100000; $ I ++ ){
08 $ array [] = md5 ($ I );
09}
10
11 // let's remove half of the array
12 for ($ I = 0; I I <100000; $ I ++ ){
13 unset ($ array [$ I]);
14}
15
16 echo "Final:". memory_get_usage (). "bytes ";
17/* prints
18. Final: 885912 bytes
19 */
20
21 echo "Peak:". memory_get_peak_usage (). "bytes ";
22/* prints
23 Peak: 13687072 bytes |