Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* BEGIN PROFILER.PHP */
- $profiler_start;
- $profiler_phases = array();
- $profiler_current;
- function profiler_start($phase) {
- global $profiler_start, $profiler_current;
- $profiler_current = $phase;
- $profiler_start = microtime();
- }
- function profiler_next($phase) {
- global $profiler_start, $profiler_current, $profiler_phases;
- $now = microtime();
- $profiler_phases[] = $profiler_current . ": " . (($now - $profiler_start) / 1000) . "ms";
- $profiler_current = $phase;
- $profiler_start = $now;
- }
- function profiler_end() {
- global $profiler_start, $profiler_current, $profiler_phases;
- $profiler_phases[] = $profiler_current . ": " . ((microtime() - $profiler_start) / 1000) . "ms";
- }
- function profiler_result() {
- global $profiler_phases;
- return implode("\n", $profiler_phases);
- }
- /* END PROFILER.PHP */
- /* BEGIN EXAMPLE USAGE */
- include "profiler.php";
- profiler_start("init");
- $f = fopen("file.txt", "w");
- profiler_next("write");
- fwrite($f, "Test String");
- profiler_next("close");
- fclose($f);
- profiler_end();
- echo profiler_result();
- /* END EXAMPLE USAGE */
- /* BEGIN EXAMPLE RESULT
- init: 50ms
- write: 100ms
- close: 30ms
- /* END EXAMPLE RESULT */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement