kdaviesnz/memoization

Wrapper for Ed Mann's memoize function

dev-master 2018-06-06 20:07 UTC

This package is not auto-updated.

Last update: 2024-04-21 07:04:54 UTC


README

Wrapper for Ed Mann's memoize function

see https://eddmann.com/posts/implementing-and-using-memoization-in-php/

Install

Via Composer

$ composer require kdaviesnz/Memoization

Usage

        $sleepz = \kdaviesnz\memoization\Memoization::memoize(function($time){
            sleep( $time );
            return true;
        });

        $firstTestStart = \microtime(true);
        $sleepz(1);
        $firstTestEnd = \microtime(true);

        $secondTestStart = \microtime(true);
        $sleepz(1);
        $secondTestEnd = \microtime(true);

        $firstTestTime = $firstTestEnd - $firstTestStart;
        $secondTestTime = $secondTestEnd - $secondTestStart;

        echo "First test took $firstTestTime ms\n";
        echo "Second test took $secondTestTime ms\n";

Change log

Please see CHANGELOG.md for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING.md and CODE_OF_CONDUCT.md for details.

Security

If you discover any security related issues, please email kdaviesnz@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see LICENSE.md for more information.

Memoization