BenchMark.object
上传用户:xiao730204
上传日期:2007-01-04
资源大小:141k
文件大小:4k
源码类别:

WEB邮件程序

开发平台:

PHP

  1. <?php
  2. class BenchMark {
  3.    var $start_time;
  4.    var $stop_time;
  5.    var $high_exec_time;
  6.    var $low_exec_time;
  7.    var $total_time;
  8.    var $avg_exec_time;
  9.    var $ignore_variables;
  10.    Function BenchMark() {
  11.       $this->start_time       = 0;
  12.       $this->stop_time        = 0;
  13.       $this->high_exec_time   = 0;
  14.       $this->low_exec_time    = 0;
  15.       $this->total_time       = 0;
  16.       $this->avg_exec_time    = 0;
  17.       $this->ignore_variables = Array();
  18.    }
  19.    Function IgnoreVar( $var_name ) {
  20.       $this->ignore_variables[ $var_name ] = 1;
  21.    }
  22.    Function UnIgnoreVar( $var_name ) {
  23.       $this->ignore_variables[ $var_name ] = 0;
  24.    }
  25.    Function IgnorePhpVars() {
  26.       $this->IgnoreVar( 'GLOBALS' );
  27.       $this->IgnoreVar( 'SCRIPT_FILENAME' );
  28.       $this->IgnoreVar( 'SCRIPT_NAME' );
  29.       $this->IgnoreVar( 'PATH_TRANSLATED' );
  30.       $this->IgnoreVar( 'PHP_SELF' );
  31.    }
  32.    Function IgnoreWebServerVars() {
  33.       $this->IgnoreVar( 'HTTP_GET_VARS' );
  34.       $this->IgnoreVar( 'HTTP_COOKIE_VARS' );
  35.       $this->IgnoreVar( 'HTTP_GET_VARS' );
  36.       $this->IgnoreVar( 'HTTP_ACCEPT' );
  37.       $this->IgnoreVar( 'HTTP_ACCEPT_CHARSET' );
  38.       $this->IgnoreVar( 'HTTP_ACCEPT_LANGUAGE' );
  39.       $this->IgnoreVar( 'HTTP_ACCEPT_ENCODING' );
  40.       $this->IgnoreVar( 'HTTP_CONNECTION' );
  41.       $this->IgnoreVar( 'HTTP_HOST' );
  42.       $this->IgnoreVar( 'HTTP_PRAGMA' );
  43.       $this->IgnoreVar( 'HTTP_USER_AGENT' );
  44.       $this->IgnoreVar( 'REMOTE_ADDR' );
  45.       $this->IgnoreVar( 'REMOTE_PORT' );
  46.       $this->IgnoreVar( 'DOCUMENT_ROOT' );
  47.       $this->IgnoreVar( 'SERVER_ADDR' );
  48.       $this->IgnoreVar( 'SERVER_ADMIN' );
  49.       $this->IgnoreVar( 'SERVER_NAME' );
  50.       $this->IgnoreVar( 'SERVER_PORT' );
  51.       $this->IgnoreVar( 'SERVER_SIGNATURE' );
  52.       $this->IgnoreVar( 'SERVER_SOFTWARE' );
  53.       $this->IgnoreVar( 'GATEWAY_INTERFACE' );
  54.       $this->IgnoreVar( 'SERVER_PROTOCOL' );
  55.       $this->IgnoreVar( 'REQUEST_METHOD' );
  56.       $this->IgnoreVar( 'QUERY_STRING' );
  57.       $this->IgnoreVar( 'REQUEST_URI' );
  58.       $this->IgnoreVar( 'REDIRECT_STATUS' );
  59.       $this->IgnoreVar( 'REDIRECT_URL' );
  60.    }
  61.    Function IgnoreUnixEnvVars() {
  62.       $this->IgnoreVar( 'PATH' );
  63.       $this->IgnoreVar( 'INIT_VERSION' );
  64.       $this->IgnoreVar( 'TERM' );
  65.       $this->IgnoreVar( 'HOSTTYPE' );
  66.       $this->IgnoreVar( 'PREVLEVEL' );
  67.       $this->IgnoreVar( 'runlevel' );
  68.       $this->IgnoreVar( 'AUTOBOOT' );
  69.       $this->IgnoreVar( 'BOOT_IMAGE' );
  70.       $this->IgnoreVar( 'CONSOLE' );
  71.       $this->IgnoreVar( 'HOME' );
  72.       $this->IgnoreVar( 'RUNLEVEL' );
  73.       $this->IgnoreVar( 'SHELL' );
  74.       $this->IgnoreVar( 'OSTYPE' );
  75.       $this->IgnoreVar( 'SHLVL' );
  76.       $this->IgnoreVar( '_' );
  77.       $this->IgnoreVar( 'previous' );
  78.    }
  79.    Function GlobalStackDump() {
  80.       echo( '<pre>' );
  81.       echo( 'Global stack dump -' . "n" );
  82.       while( list( $key, $value ) = each( $GLOBALS ) ) {
  83.          if ( $this->ignore_variables[ $key ] != 1 ) {
  84.             echo( 'Variable name : ' . $key . "n" );
  85.             var_dump( $GLOBALS[ $key ] );
  86.             echo( "n" );
  87.          }
  88.       }
  89.       echo( '</pre>' );
  90.    }
  91.    Function GetMicroTime() {
  92.       $mtime = microtime();
  93.       $mtime = explode( ' ' , $mtime );
  94.       $mtime = $mtime[ 1 ] + $mtime[ 0 ] ;
  95.       return $mtime;
  96.    }
  97.    Function Start() {
  98.       $this->start_time = $this->GetMicroTime();
  99.    }
  100.    Function Stop() {
  101.       $this->stop_time = $this->GetMicroTime();
  102.    }
  103.    Function Iterate( $code_segment, $test_times ) {
  104.       for( $i = 0; $i < $test_times; $i++ ) {
  105.          $this->Start();
  106.          eval( $code_segment );
  107.          $this->Stop();
  108.          $this->NextLoopIteration();
  109.       }
  110.       $this->CalculateAvg( $test_times );
  111.    }
  112.    Function NextLoopIteration() {
  113.       $overall_time = 0;
  114.       $overall_time = $this->stop_time - $this->start_time;
  115.       $this->total_time = $this->total_time + $overall_time;
  116.       if ( $overall_time > $this->high_exec_time ) {
  117.          $this->high_exec_time = $overall_time;
  118.       }
  119.       if ( $overall_time < $this->low_exec_time ) {
  120.          $this->low_exec_time = $overall_time;
  121.       }
  122.    }
  123.    Function CalculateAvg( $test_times ) {
  124.       $this->avg_exec_time = $this->total_time / $test_times;
  125.    }
  126. }
  127. ?>