Skip to content

Instantly share code, notes, and snippets.

@yvmarques
Created May 29, 2013 12:39
Show Gist options
  • Save yvmarques/5669977 to your computer and use it in GitHub Desktop.
Save yvmarques/5669977 to your computer and use it in GitHub Desktop.
<?php
# Bench functional programming
$start = microtime(true);
$fact = function($x, $y = 1) use (&$fact) {
if ($x == 0) {
return $y;
}
return $fact($x - 1, $y * $x);
};
$fact(30000) . "\n";
echo (microtime(true) - $start) * 1000 . "\n";
# Bench traditionnal programming
$start = microtime(true);
function recurv($x, $y = 1) {
if ($x == 0) {
return 1;
}
return recurv($x - 1, $x * $y);
}
recurv(30000) . "\n";
echo (microtime(true) - $start) * 1000 . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment