-
-
Save oliuz/9e67e3ff590d22a141a65b7622f1091c to your computer and use it in GitHub Desktop.
A simple helper function and macro for timing php scripts and eloquent queries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Helper function. | |
| if (! function_exists('timer')) { | |
| function timer($expression) | |
| { | |
| $start = microtime(true); | |
| if ($expression instanceof Closure) { | |
| $expression(); | |
| } else { | |
| eval(rtrim($expression, ';') . ';'); | |
| } | |
| return microtime(true) - $start . " Seconds"; | |
| } | |
| } | |
| // Query builder macro. | |
| Illuminate\Database\Eloquent\Builder::macro('timer', function() { | |
| $start = microtime(true); | |
| $this->get(); | |
| return microtime(true) - $start . " Seconds"; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment