Magnus Manske wrote:
I vaguely remember that the profiling functions (wfProfileIn/wfProfileOut) use up a lot of processor time, even when empty.
I think that's a bit of an exaggeration. I just measured a time of 3.2us per pair with it off, and 44us per pair with it on. The test was performed on zwinger, here is the code:
<?php require_once("commandLine.inc"); $n = 10000000; $t = getmicrotime();
for ( $i=0; $i<$n; $i++ );
$t -= 2*getmicrotime();
for ( $i=0; $i<$n; $i++ ) { wfProfileIn('test'); wfProfileOut('test'); }
$t += getmicrotime(); print $t / $n . "us/iteration\n";
function getmicrotime(){ static $initial = false; list($usec, $sec) = explode(" ",microtime()); if ( !$initial ) { $initial = (float)$sec; }
return ((float)$usec * 1000000 + ((int)$sec-$initial) * 1000000); } ?>
Profile runs on the live site suggest that when switched on, wfProfileIn() and wfProfileOut() use about 4% of execution time, so it would follow that when switched off, they use on the order of tenths of a percent.
By contrast Julian Ostrow, a new MediaWiki developer, is coding a feature which will reduce to near-nothing the cost of existence test queries, which have been observed to use up to 37% of execution time on the live site, when the DB is under high load.
I just saw the PHP "define" function, which seems to work similar to the C++ preprocessor #define statement.
Would it be possible to "define" the profiling function names once, and define them as empty (or something) for running code? That would eliminate the need for the function call.
I'm not sure that this is possible in PHP, however.
It's not. The define statement makes a constant, not a macro. In C++ terms, it's closer to "const int x=5;" than "#define X 5"
-- Tim Starling