← All changes
|
src/extra/php-codesniffer-php-token/Util/Timing.php
+55
-58
3.1.0
→
6.3.0
View file →
| @@ -8,79 +8,76 @@ | ||
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | namespace PHP_CodeSniffer\Util; |
| 11 | 11 | |
| 12 | -class Timing | |
| 13 | -{ | |
| 12 | +class Timing { | |
| 14 | 13 | |
| 15 | - /** | |
| 16 | - * The start time of the run. | |
| 17 | - * | |
| 18 | - * @var float | |
| 19 | - */ | |
| 20 | - private static $startTime; | |
| 14 | + /** | |
| 15 | + * The start time of the run. | |
| 16 | + * | |
| 17 | + * @var float | |
| 18 | + */ | |
| 19 | + private static $startTime; | |
| 21 | 20 | |
| 22 | - /** | |
| 23 | - * Used to make sure we only print the run time once per run. | |
| 24 | - * | |
| 25 | - * @var boolean | |
| 26 | - */ | |
| 27 | - private static $printed = false; | |
| 21 | + /** | |
| 22 | + * Used to make sure we only print the run time once per run. | |
| 23 | + * | |
| 24 | + * @var boolean | |
| 25 | + */ | |
| 26 | + private static $printed = false; | |
| 28 | 27 | |
| 29 | 28 | |
| 30 | - /** | |
| 31 | - * Start recording time for the run. | |
| 32 | - * | |
| 33 | - * @return void | |
| 34 | - */ | |
| 35 | - public static function startTiming() | |
| 36 | - { | |
| 29 | + /** | |
| 30 | + * Start recording time for the run. | |
| 31 | + * | |
| 32 | + * @return void | |
| 33 | + */ | |
| 34 | + public static function startTiming() { | |
| 37 | 35 | |
| 38 | - self::$startTime = microtime(true); | |
| 36 | + self::$startTime = microtime( true ); | |
| 39 | 37 | |
| 40 | - }//end startTiming() | |
| 38 | + }//end startTiming() | |
| 41 | 39 | |
| 42 | 40 | |
| 43 | - /** | |
| 44 | - * Print information about the run. | |
| 45 | - * | |
| 46 | - * @param boolean $force If TRUE, prints the output even if it has | |
| 47 | - * already been printed during the run. | |
| 48 | - * | |
| 49 | - * @return void | |
| 50 | - */ | |
| 51 | - public static function printRunTime($force=false) | |
| 52 | - { | |
| 53 | - if ($force === false && self::$printed === true) { | |
| 54 | - // A double call. | |
| 55 | - return; | |
| 56 | - } | |
| 41 | + /** | |
| 42 | + * Print information about the run. | |
| 43 | + * | |
| 44 | + * @param boolean $force If TRUE, prints the output even if it has | |
| 45 | + * already been printed during the run. | |
| 46 | + * | |
| 47 | + * @return void | |
| 48 | + */ | |
| 49 | + public static function printRunTime( $force = false ) { | |
| 50 | + if ( $force === false && self::$printed === true ) { | |
| 51 | + // A double call. | |
| 52 | + return; | |
| 53 | + } | |
| 57 | 54 | |
| 58 | - if (self::$startTime === null) { | |
| 59 | - // Timing was never started. | |
| 60 | - return; | |
| 61 | - } | |
| 55 | + if ( self::$startTime === null ) { | |
| 56 | + // Timing was never started. | |
| 57 | + return; | |
| 58 | + } | |
| 62 | 59 | |
| 63 | - $time = ((microtime(true) - self::$startTime) * 1000); | |
| 60 | + $time = ( ( microtime( true ) - self::$startTime ) * 1000 ); | |
| 64 | 61 | |
| 65 | - if ($time > 60000) { | |
| 66 | - $mins = floor($time / 60000); | |
| 67 | - $secs = round((($time % 60000) / 1000), 2); | |
| 68 | - $time = $mins.' mins'; | |
| 69 | - if ($secs !== 0) { | |
| 70 | - $time .= ", $secs secs"; | |
| 71 | - } | |
| 72 | - } else if ($time > 1000) { | |
| 73 | - $time = round(($time / 1000), 2).' secs'; | |
| 74 | - } else { | |
| 75 | - $time = round($time).'ms'; | |
| 76 | - } | |
| 62 | + if ( $time > 60000 ) { | |
| 63 | + $mins = floor( $time / 60000 ); | |
| 64 | + $secs = round( ( ( $time % 60000 ) / 1000 ), 2 ); | |
| 65 | + $time = $mins . ' mins'; | |
| 66 | + if ( $secs !== 0 ) { | |
| 67 | + $time .= ", $secs secs"; | |
| 68 | + } | |
| 69 | + } else if ( $time > 1000 ) { | |
| 70 | + $time = round( ( $time / 1000 ), 2 ) . ' secs'; | |
| 71 | + } else { | |
| 72 | + $time = round( $time ) . 'ms'; | |
| 73 | + } | |
| 77 | 74 | |
| 78 | - $mem = round((memory_get_peak_usage(true) / (1024 * 1024)), 2).'MB'; | |
| 79 | - echo "Time: $time; Memory: $mem".PHP_EOL.PHP_EOL; | |
| 75 | + $mem = round( ( memory_get_peak_usage( true ) / ( 1024 * 1024 ) ), 2 ) . 'MB'; | |
| 76 | + echo "Time: $time; Memory: $mem" . PHP_EOL . PHP_EOL; | |
| 80 | 77 | |
| 81 | - self::$printed = true; | |
| 78 | + self::$printed = true; | |
| 82 | 79 | |
| 83 | - }//end printRunTime() | |
| 80 | + }//end printRunTime() | |
| 84 | 81 | |
| 85 | 82 | |
| 86 | 83 | }//end class |