For a long time, ThinkPHP has to use the debug_start, debug_end methods, and even the Debug class to complete those debugging functions. In ThinkPHP3.1, these complex functions are replaced by a simple G method, this cannot be said to be a gorgeous upgrade.
The G method can be used to mark the location and interval statistics. The following describes the specific usage:
1. Mark the location
The first use of the G method is to mark the position, for example:
G('begin');
Mark the current location as the begin tag and record the execution time of the current location. If the environment supports this, it can also record memory usage. You can call the G method flag anywhere.
2. Running time statistics
After the position is marked, we can call the G method again for Interval statistics, for example:
G ('begin ');//... other code snippet G ('end ');//... maybe there are other codes // echo G ('begin', 'end') in the statistical interval '). 'S ';
G ('begin', 'end') indicates the execution time from the begin position to the end position (in seconds). begin must be a marked position, if the end position is not marked at this time, the current position is automatically marked as the end label. The output result is similar:
0.0056s
The default statistical accuracy is the fourth digit after the decimal point. If you think this statistical accuracy is not enough, you can set it as follows:
G('begin','end',6).'s';
The possible output will be:
0.005587s
3. memory overhead statistics
If your environment supports memory usage statistics, you can also use the G method for Interval memory overhead statistics (unit: kb), for example:
echo G('begin','end','m').'kb';
The third parameter uses m for memory overhead statistics. The output result may be:
625kb
Similarly,If the end label is not marked, the current position is automatically marked as the end label first..
If the environment does not support memory statistics, this parameter is invalid and the interval running time statistics are still performed.
Forget debug_start and debug_end. The greatest truths are simple, you know ~