PHP code example of ganglio / memoizer
1. Go to this page and download the library: Download ganglio/memoizer library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ganglio / memoizer example snippets
$myFunc = function ($a) {
return $a * mt_rand();
}
$myMemoizedFunc = new Memoizer($myFunc);
echo "Returns: " . $myMemoizedFunc(3) . "\n";
echo "Returns the same value: " . $myMemoizedFunc(3) . "\n";
$mySlowFunc = function ($a) {
sleep(5);
return $a * mt_rand();
}
$myMemoizedSlowFunc = new Memoizer($mySlowFunc);
$st = time();
echo "Returns: " . $myMemoizedSlowFunc(3) . " in: " . (time() - $st);
$st = time();
echo "Returns the same value: " . $myMemoizedSlowFunc(3) . " in basically 0 time: " . (time() - $st);