Created
February 29, 2012 21:35
-
-
Save enumag/1944602 to your computer and use it in GitHub Desktop.
Incrementation test
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 | |
| class Timer { | |
| public static $time = array(); | |
| public static $last; | |
| public static function start($name = NULL) { | |
| static $i = 0; | |
| if ($name === NULL) { | |
| $name = $i++; | |
| } | |
| self::$last = $name; | |
| self::$time[$name] = microtime(TRUE); | |
| } | |
| public static function stop($name = NULL) { | |
| if ($name === NULL) { | |
| $name = self::$last; | |
| } | |
| self::$time[$name] = (microtime(TRUE) - self::$time[$name]) * 1000; | |
| } | |
| public static function table() { | |
| if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') | |
| return; | |
| echo '<div style="position: fixed; bottom: 30%; right: 15%; z-index: 999; background-color: lightgray; padding: 15px; font-size: 13px;">'; | |
| echo '<table>'; | |
| foreach (self::$time as $key => $value) { | |
| echo '<tr><td style="padding: 2px 5px">' . $key . '</td><td>' . round($value) . ' ms</td></tr>'; | |
| } | |
| echo '</table>'; | |
| echo '</div>'; | |
| } | |
| } | |
| register_shutdown_function(array('Timer', 'table')); | |
| function start($name = NULL) { | |
| Timer::start($name); | |
| } | |
| function stop($name = NULL) { | |
| Timer::stop($name); | |
| } | |
| function flip($name = NULL) { | |
| Timer::stop(); | |
| Timer::start($name); | |
| } | |
| start(); | |
| for ($i = 1; $i <= 10000000; $i++); | |
| for ($i = 1; $i <= 10000000; $i++); | |
| for ($i = 1; $i <= 10000000; $i++); | |
| for ($i = 1; $i <= 10000000; $i++); | |
| for ($i = 1; $i <= 10000000; $i++); | |
| flip(); | |
| for ($i = 1; $i <= 10000000; ++$i); | |
| for ($i = 1; $i <= 10000000; ++$i); | |
| for ($i = 1; $i <= 10000000; ++$i); | |
| for ($i = 1; $i <= 10000000; ++$i); | |
| for ($i = 1; $i <= 10000000; ++$i); | |
| stop(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment