2017 © Pedro PelĂĄez
 

library memoize

A simple memoization function

image

kanellov/memoize

A simple memoization function

  • Monday, March 16, 2015
  • by kanellov
  • Repository
  • 1 Watchers
  • 0 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

memoize

master: Build Status develop: Build Status, (*1)

A simple memoization function, (*2)

Installation

Install composer in your project:, (*3)

curl -s https://getcomposer.org/installer | php

Create a composer.json file in your project root:, (*4)

{
    "require": {
        "kanellov/memoize": "dev-master"
    }
}

Install via composer:, (*5)

php composer.phar install

Add this line to your application’s index.php file:, (*6)

<?php
require 'vendor/autoload.php';

System Requirements

You need PHP >= 5.3.0., (*7)

Example

<?php
require 'vendor/autoload.php';

function benchmark($name, $runs, $function)
{
    $start = microtime(true);
    while ($runs--) {
        $function();
    }
    $end = microtime(true);

    return sprintf('%s: %s', $name, ($end - $start)) . PHP_EOL;
}

function heavyCalc($varA, $varB)
{
    usleep(100);
    return $varA + $varB;
}

$memoized = Knlv\memoize('heavyCalc');

echo benchmark('heavyCalc(1, 2)', 100, function() {
    heavyCalc(1, 2);
});

echo benchmark('Memoized heavyCalc(1, 2)', 100, function () use (&$memoized) {
    $memoized(1, 2);
});

/*
heavyCalc(1, 2): 0.016629219055176
Memoized heavyCalc(1, 2): 0.001600980758667
*/

The Versions

16/03 2015

dev-master

9999999-dev https://github.com/kanellov/memoize

A simple memoization function

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

function memoize

16/03 2015

dev-develop

dev-develop https://github.com/kanellov/memoize

A simple memoization function

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

function memoize

16/03 2015

0.1.0

0.1.0.0 https://github.com/kanellov/memoize

A simple memoization function

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

function memoize