- <?php
- class BenchMark {
- var $start_time;
- var $stop_time;
- var $high_exec_time;
- var $low_exec_time;
- var $total_time;
- var $avg_exec_time;
- var $ignore_variables;
- Function BenchMark() {
- $this->start_time = 0;
- $this->stop_time = 0;
- $this->high_exec_time = 0;
- $this->low_exec_time = 0;
- $this->total_time = 0;
- $this->avg_exec_time = 0;
- $this->ignore_variables = Array();
- }
- Function IgnoreVar( $var_name ) {
- $this->ignore_variables[ $var_name ] = 1;
- }
- Function UnIgnoreVar( $var_name ) {
- $this->ignore_variables[ $var_name ] = 0;
- }
- Function IgnorePhpVars() {
- $this->IgnoreVar( 'GLOBALS' );
- $this->IgnoreVar( 'SCRIPT_FILENAME' );
- $this->IgnoreVar( 'SCRIPT_NAME' );
- $this->IgnoreVar( 'PATH_TRANSLATED' );
- $this->IgnoreVar( 'PHP_SELF' );
- }
- Function IgnoreWebServerVars() {
- $this->IgnoreVar( 'HTTP_GET_VARS' );
- $this->IgnoreVar( 'HTTP_COOKIE_VARS' );
- $this->IgnoreVar( 'HTTP_GET_VARS' );
- $this->IgnoreVar( 'HTTP_ACCEPT' );
- $this->IgnoreVar( 'HTTP_ACCEPT_CHARSET' );
- $this->IgnoreVar( 'HTTP_ACCEPT_LANGUAGE' );
- $this->IgnoreVar( 'HTTP_ACCEPT_ENCODING' );
- $this->IgnoreVar( 'HTTP_CONNECTION' );
- $this->IgnoreVar( 'HTTP_HOST' );
- $this->IgnoreVar( 'HTTP_PRAGMA' );
- $this->IgnoreVar( 'HTTP_USER_AGENT' );
- $this->IgnoreVar( 'REMOTE_ADDR' );
- $this->IgnoreVar( 'REMOTE_PORT' );
- $this->IgnoreVar( 'DOCUMENT_ROOT' );
- $this->IgnoreVar( 'SERVER_ADDR' );
- $this->IgnoreVar( 'SERVER_ADMIN' );
- $this->IgnoreVar( 'SERVER_NAME' );
- $this->IgnoreVar( 'SERVER_PORT' );
- $this->IgnoreVar( 'SERVER_SIGNATURE' );
- $this->IgnoreVar( 'SERVER_SOFTWARE' );
- $this->IgnoreVar( 'GATEWAY_INTERFACE' );
- $this->IgnoreVar( 'SERVER_PROTOCOL' );
- $this->IgnoreVar( 'REQUEST_METHOD' );
- $this->IgnoreVar( 'QUERY_STRING' );
- $this->IgnoreVar( 'REQUEST_URI' );
- $this->IgnoreVar( 'REDIRECT_STATUS' );
- $this->IgnoreVar( 'REDIRECT_URL' );
- }
- Function IgnoreUnixEnvVars() {
- $this->IgnoreVar( 'PATH' );
- $this->IgnoreVar( 'INIT_VERSION' );
- $this->IgnoreVar( 'TERM' );
- $this->IgnoreVar( 'HOSTTYPE' );
- $this->IgnoreVar( 'PREVLEVEL' );
- $this->IgnoreVar( 'runlevel' );
- $this->IgnoreVar( 'AUTOBOOT' );
- $this->IgnoreVar( 'BOOT_IMAGE' );
- $this->IgnoreVar( 'CONSOLE' );
- $this->IgnoreVar( 'HOME' );
- $this->IgnoreVar( 'RUNLEVEL' );
- $this->IgnoreVar( 'SHELL' );
- $this->IgnoreVar( 'OSTYPE' );
- $this->IgnoreVar( 'SHLVL' );
- $this->IgnoreVar( '_' );
- $this->IgnoreVar( 'previous' );
- }
- Function GlobalStackDump() {
- echo( '<pre>' );
- echo( 'Global stack dump -' . "n" );
- while( list( $key, $value ) = each( $GLOBALS ) ) {
- if ( $this->ignore_variables[ $key ] != 1 ) {
- echo( 'Variable name : ' . $key . "n" );
- var_dump( $GLOBALS[ $key ] );
- echo( "n" );
- }
- }
- echo( '</pre>' );
- }
- Function GetMicroTime() {
- $mtime = microtime();
- $mtime = explode( ' ' , $mtime );
- $mtime = $mtime[ 1 ] + $mtime[ 0 ] ;
- return $mtime;
- }
- Function Start() {
- $this->start_time = $this->GetMicroTime();
- }
- Function Stop() {
- $this->stop_time = $this->GetMicroTime();
- }
- Function Iterate( $code_segment, $test_times ) {
- for( $i = 0; $i < $test_times; $i++ ) {
- $this->Start();
- eval( $code_segment );
- $this->Stop();
- $this->NextLoopIteration();
- }
- $this->CalculateAvg( $test_times );
- }
- Function NextLoopIteration() {
- $overall_time = 0;
- $overall_time = $this->stop_time - $this->start_time;
- $this->total_time = $this->total_time + $overall_time;
- if ( $overall_time > $this->high_exec_time ) {
- $this->high_exec_time = $overall_time;
- }
- if ( $overall_time < $this->low_exec_time ) {
- $this->low_exec_time = $overall_time;
- }
- }
- Function CalculateAvg( $test_times ) {
- $this->avg_exec_time = $this->total_time / $test_times;
- }
- }
- ?>