Last active
July 24, 2018 12:36
-
-
Save predakanga/22e5b427c948071e8d292ed9b5c95c56 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function indirectStringToUpper($word) { | |
return strtoupper($word); | |
} | |
class FuncBench { | |
public function benchLoopDirectFunction() { | |
$words = ['i', 'am', 'not', 'shouting']; | |
$shouts = []; | |
foreach($words as $word) { | |
$shouts[] = strtoupper($word); | |
} | |
} | |
public function benchLoopIndirectFunction() { | |
$words = ['i', 'am', 'not', 'shouting']; | |
$shouts = []; | |
foreach($words as $word) { | |
$shouts[] = indirectStringToUpper($word); | |
} | |
} | |
public function benchLoopClosure() { | |
$words = ['i', 'am', 'not', 'shouting']; | |
$shouts = []; | |
$closure = function($word) { | |
return strtoupper($word); | |
}; | |
foreach($words as $word) { | |
$shouts[] = $closure($word); | |
} | |
} | |
public function benchMapDirectFunction() { | |
$words = ['i', 'am', 'not', 'shouting']; | |
$shouts = []; | |
$shouts = array_map('strtoupper', $words); | |
} | |
public function benchMapIndirectFunction() { | |
$words = ['i', 'am', 'not', 'shouting']; | |
$shouts = []; | |
$shouts = array_map('indirectStringToUpper', $words); | |
} | |
public function benchMapClosure() { | |
$words = ['i', 'am', 'not', 'shouting']; | |
$shouts = []; | |
$shouts = array_map(function($word) { | |
return strtoupper($word); | |
}, $words); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment