Re: [PHP3] Re: [PHP-DEV] Re: [PHP3] PHP Speed Optimization

From: Date: Mon, 24 Apr 2000 20:53:35 +0000
Subject: Re: [PHP3] Re: [PHP-DEV] Re: [PHP3] PHP Speed Optimization
References: 1 2 3 4 5  Groups: php.dev 
Request: Send a blank email to php-dev+get-18157@lists.php.net to get a copy of this message
| Say you have 30 user-built functions in *one* file, 200 lines of code. | Depending on your code base/version, if those are called 10 times per page, | you need to include that code for the parser (file call), and | then as you go through the page, it substitutes out the function code.... | plus you've added 20 useless functions of overhead for *every* | parsed page. (Hence, the speed differences between 3 and 4, and the | problem with using functions in 3. They *will* bog your execution | down) Its there parsed once sitting in the memory, it doesn't actually substitute the function contents with the function call and then process is as if it was embedded in the code itself! Its done through a smart method. | | Lots and lots of overhead in that. If you can strip excess functions | out, and speed is your goal, by all means, dump them over the side | as fast as you can, and explicitly code using PHP's internal | functions. Try two or three variants on your code, to see if, for | example, you could get a faster result from a printf or an echo, | a faster loop by only testing (if/case) under a smaller set of | circumstances, and, if you can, avoid *ever* using requires or | includes.... Seems like you have mixed C with PHP. PHP functions don't have overhead like C does (unless they are inline, the overhead is negligible, but its there!) | | If that's still not fast enough, look into coding directly in | C. You will choose PHP when you don't need C or you need rapid development with easy interchangeable database connectivity and blah blah. | | Now, of course, this all makes for faster execution, but your | code can bloat like mad, or become almost unreadable. If the goal, | however, is speed, that is a sacrifice you may *have* to make... This might look like a silly example, but it demonstrates the goal. I don't use PHP3, sorry. This is done with PHP4 (CVS, not latest). <? for ( $i = 0 ; $i < 100000 ; $i++ ) $array[$i] = $i . "COOOOLLLLLLLLLLLLASDFWMASDFMASDGN#@"; $cnt = 0; $now = time(); while ( $x = current ( $array ) ) { if ( ++$cnt % 2 == 0 ) { $cnt++; $z .= "a"; $z .= "b"; $z .= "c"; $z .= "d"; $z .= "e"; $z .= "f"; $z .= "g"; $z .= "h"; $z .= "j"; $z .= "k"; $z .= "sdf"; $z .= "1"; $z .= "`"; $z .= "42"; $z .= "x"; $z .= "aasd"; $z .= "1a"; $z .= "23a"; $z = sin ( $i ); $z = strrev ( $z ); $z = join ( "!" , split ( "." , $z ) ); ereg ( "#@" , $z , $y ); next ( $array ); } else { $y = soundex ( $z ); $a = similar_text ( $y , $z ); $b = sprintf ( "%.50f" , $z ); $z = strrev ( str_replace ( "a" , "b" , AddSlashes ( join ( "." , split ( "." , join ( "." , split ( "." , $z ) ) ) ) ) ) ); } } $n = time(); print "Took: ($now-$n) " . ( $n- $now ) . " seconds"; ?> Three runs: All report 36 seconds. <? for ( $i = 0 ; $i < 100000 ; $i++ ) $array[$i] = $i . "COOOOLLLLLLLLLLLLASDFWMASDFMASDGN#@"; $cnt = 0; $now = time(); while ( $x = current ( $array ) ) { if ( ++$cnt % 2 == 0 ) func1(&$z); else func2(&$z); next ( $array ); } $n = time(); print "Took: ($now-$n) " . ( $n- $now ) . " seconds"; function func1 ( $z ) { $cnt++; $z .= "a"; $z .= "b"; $z .= "c"; $z .= "d"; $z .= "e"; $z .= "f"; $z .= "g"; $z .= "h"; $z .= "j"; $z .= "k"; $z .= "sdf"; $z .= "1"; $z .= "`"; $z .= "42"; $z .= "x"; $z .= "aasd"; $z .= "1a"; $z .= "23a"; $z = sin ( $i ); $z = strrev ( $z ); $z = join ( "!" , split ( "." , $z ) ); ereg ( "#@" , $z , $y ); } function func2 ( $z ) { $y = soundex ( $z ); $a = similar_text ( $y , $z ); $b = sprintf ( "%.50f" , $z ); $z = strrev ( str_replace ( "a" , "b" , AddSlashes ( join ( "." , split ( "." , join ( "." , split ( "." , $z ) ) ) ) ) ) ); } ?> Three runs: All report 22 seconds. On Windows 2000, 192 (128+64)mb of ram with all other programs shutdown for testing..... What do you say now? Thanks. Faisal

« previous php.dev (#18157) next »