| Short description: |
A method that speeds methods up at the cost of memory |
| Category: |
Library/Cache |
| Status: |
stable |
| Created: |
2005-09-09 21:15:41 GMT |
| Last update: |
2006-02-02 17:48:36 GMT |
| Owner: |
Daniel J. Berger
(Projects of this owner) |
| Homepage: |
http://www.rubyforge.org/projects/shards |
| Download: |
http://rubyforge.org/frs/download.php/8365/memoize-1.2.1.tar.gz
|
| License: |
Ruby's |
| Dependency: |
|
| Description: |
A method that speeds methods up at the cost of memory (or disk space).
require "memoize"
include Memoize
# Inefficient fibonacci method
def fib(n)
return n if n < 2
fib(n-1) + fib(n-2)
end
fib(100) # Slow
memoize(:fib)
fib(100) # Fast
memoize(:fib, "fib.cache")
fib(100) # Fast
|
| Versions: |
[1.2.3 (2007-05-24)]
[1.2.2 (2006-02-04)]
[1.2.1 (2006-02-02)]
[1.2.0 (2006-01-01)]
[1.1.0 (2005-10-22)]
[1.0.0 (2005-09-09)]
|