PageRenderTime 61ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/kint/parsers/custom/microtime.php

https://bitbucket.org/zilog/as-his-profession
PHP | 30 lines | 23 code | 7 blank | 0 comment | 4 complexity | 1436d20617d200b7517171dad6851a01 MD5 | raw file
  1. <?php
  2. class Kint_Parsers_Microtime extends kintParser
  3. {
  4. private static $_times = array();
  5. protected function _parse( & $variable )
  6. {
  7. if ( !is_string( $variable ) || !preg_match( '[0\.[0-9]{8} [0-9]{10}]', $variable ) ) {
  8. return false;
  9. }
  10. list( $usec, $sec ) = explode( " ", microtime() );
  11. $time = ( (float)$usec + (float)$sec );
  12. $this->value = @date( 'Y-m-d H:i:s', $sec ) . '.' . substr( $usec, 2, -2 );
  13. $numberOfCalls = count( self::$_times );
  14. if ( $numberOfCalls > 0 ) { # meh, faster than count($times) > 1
  15. $this->value .= "\n<strong>SINCE LAST CALL:</strong> " . ( $time - end( self::$_times ) ) . 's.';
  16. if ( $numberOfCalls > 1 ) {
  17. $this->value .= "\n<strong>SINCE START:</strong> " . ( $time - self::$_times[0] ) . 's.';
  18. }
  19. }
  20. self::$_times[] = $time;
  21. $this->type = 'Microtime';
  22. }
  23. }