Comment: | Cache the results of wfIsWindows()
Each php_uname() call produces a uname syscall.
The cached one is three times faster (3.197545885) which is liklely to be the difference between a php var lookup and a syscall on my system.
== Test script ==
<?php
function wfIsWindows() {
if ( substr( php_uname(), 0, 7 ) == 'Windows' ) {
return true;
} else {
return false;
}
}
function wfIsWindowsCached() {
static $isWindows = null;
if ( $isWindows === null ) {
$isWindows = substr( php_uname(), 0, 7 ) == 'Windows';
}
return $isWindows;
}
$win = $nonwin = 0;
$time = microtime( true );
for ( $i = 1; $i < 5e8; $i++ ) {
if ( wfIsWindowsCached() ) {
$win++;
} else {
$nonwin++;
}
}
$time = microtime( true ) - $time;
echo "Time elapsed: $time\n"; |