3 class Kint_Parsers_Microtime extends kintParser
5 private static $_times = array();
6 private static $_laps = array();
8 protected function _parse( & $variable )
10 if ( !is_string( $variable ) || !preg_match( '[0\.[0-9]{8} [0-9]{10}]', $variable ) ) {
14 list( $usec, $sec ) = explode( " ", $variable );
16 $time = (float) $usec + (float) $sec;
18 $size = memory_get_usage( true );
21 # '@' is used to prevent the dreaded timezone not set error
22 $this->value = @date( 'Y-m-d H:i:s', $sec ) . '.' . substr( $usec, 2, 4 );
24 $numberOfCalls = count( self::$_times );
25 if ( $numberOfCalls > 0 ) { # meh, faster than count($times) > 1
26 $lap = $time - end( self::$_times );
27 self::$_laps[] = $lap;
29 $this->value .= "\n<b>SINCE LAST CALL:</b> <b class=\"kint-microtime\">" . round( $lap, 4 ) . '</b>s.';
30 if ( $numberOfCalls > 1 ) {
31 $this->value .= "\n<b>SINCE START:</b> " . round( $time - self::$_times[0], 4 ) . 's.';
32 $this->value .= "\n<b>AVERAGE DURATION:</b> "
33 . round( array_sum( self::$_laps ) / $numberOfCalls, 4 ) . 's.';
37 $unit = array( 'B', 'KB', 'MB', 'GB', 'TB' );
39 $this->value .= "\n<b>MEMORY USAGE:</b> " . $size . " bytes ("
40 . round( $size / pow( 1024, ( $i = floor( log( $size, 1024 ) ) ) ), 3 ) . ' ' . $unit[ $i ] . ")";
43 self::$_times[] = $time;
44 $this->type = 'Stats';
49 d( 'start', microtime() );
50 for ( $i = 0; $i < 10; $i++ ) {
52 $duration = mt_rand( 0, 200000 ), // the reported duration will be larger because of Kint overhead