Cache the results of wfIsWindows()
authorPlatonides <platonides@users.mediawiki.org>
Tue, 26 Oct 2010 15:14:56 +0000 (15:14 +0000)
committerPlatonides <platonides@users.mediawiki.org>
Tue, 26 Oct 2010 15:14:56 +0000 (15:14 +0000)
commit0b7e7be4ccb12e4e4125bb51726b319948e620f8
tree036de2e3f07da88a92b3c7fca8e7bc47be08f9b9
parentff14cd20a30978eb64a9ca375e30619de6546045
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";
includes/GlobalFunctions.php