Download Shareware and Freeware Software for Windows, Linux, Macintosh, PDA

line Home  |  About Us  |  Link To Us  |  FAQ  |  Contact

Serving Software Downloads in 976 Categories, Downloaded 29.545.093 Times

Memoize 1.01

  Date Added: September 01, 2010  |  Visits: 578


Report Broken Link
Printer Friendly Version

Product Homepage
Download (70 downloads)

Memoize - Make functions faster by trading space for time. SYNOPSIS # This is the documentation for Memoize 1.01 use Memoize; memoize(slow_function); slow_function(arguments); # Is faster than it was before This is normally all you need to know. However, many options are available: memoize(function, options...); Options include: NORMALIZER => function INSTALL => new_name SCALAR_CACHE => MEMORY SCALAR_CACHE => [HASH, %cache_hash ] SCALAR_CACHE => FAULT SCALAR_CACHE => MERGE LIST_CACHE => MEMORY LIST_CACHE => [HASH, %cache_hash ] LIST_CACHE => FAULT LIST_CACHE => MERGE `Memoizing a function makes it faster by trading space for time. It does this by caching the return values of the function in a table. If you call the function again with the same arguments, memoize jumps in and gives you the value out of the table, instead of letting the function compute the value all over again. Here is an extreme example. Consider the Fibonacci sequence, defined by the following function: # Compute Fibonacci numbers sub fib { my $n = shift; return $n if $n < 2; fib($n-1) + fib($n-2); } This function is very slow. Why? To compute fib(14), it first wants to compute fib(13) and fib(12), and add the results. But to compute fib(13), it first has to compute fib(12) and fib(11), and then it comes back and computes fib(12) all over again even though the answer is the same. And both of the times that it wants to compute fib(12), it has to compute fib(11) from scratch, and then it has to do it again each time it wants to compute fib(13). This function does so much recomputing of old results that it takes a really long time to run---fib(14) makes 1,200 extra recursive calls to itself, to compute and recompute things that it already computed. This function is a good candidate for memoization. If you memoize the `fib function above, it will compute fib(14) exactly once, the first time it needs to, and then save the result in a table. Then if you ask for fib(14) again, it gives you the result out of the table. While computing fib(14), instead of computing fib(12) twice, it does it once; the second time it needs the value it gets it from the table. It doesnt compute fib(11) four times; it computes it once, getting it from the table the next three times. Instead of making 1,200 recursive calls to `fib, it makes 15. This makes the function about 150 times faster. You could do the memoization yourself, by rewriting the function, like this: # Compute Fibonacci numbers, memoized version { my @fib; sub fib { my $n = shift; return $fib[$n] if defined $fib[$n]; return $fib[$n] = $n if $n < 2; $fib[$n] = fib($n-1) + fib($n-2); } } Or you could use this module, like this: use Memoize; memoize(fib); # Rest of the fib function just like the original version. This makes it easy to turn memoizing on and off. Heres an even simpler example: I wrote a simple ray tracer; the program would look in a certain direction, figure out what it was looking at, and then convert the `color value (typically a string like `red) of that object to a red, green, and blue pixel value, like this: for ($direction = 0; $direction < 300; $direction++) { # Figure out which object is in direction $direction $color = $object->{color}; ($r, $g, $b) = @{&ColorToRGB($color)}; ... } Since there are relatively few objects in a picture, there are only a few colors, which get looked up over and over again. Memoizing ColorToRGB sped up the program by several percent..

Requirements: No special requirements
Platforms: Linux
Keyword: Cache Compute Faster Fib Function Libraries List Make Functions Memoize Programming Scalar
Users rating: 0/10

License: Freeware Size: 47.1 KB
More Reviews or Write Review

Libraries  -  Libslack 0.5.2
Libslack is a library of general utilities designed to make UNIX/C programming a bit easier on the eye. It is a seemingly random collection of modules and functions that I find commonly useful. It was originally implemented as part of the daemon...
317.44 KB  
Miscellaneous  -  List Tools 1.0
This script presents you a collection of some useful list-related functions.
Utilities  -  Cache Speed 2.1
Cache Speed is a simple tool to make your computer go faster. It changes some basic settings in your system.ini file. Cache Speed also optimizes your current physical RAM, giving your computer the fresh feel that it has when you reboot it. Cache...
1.18 MB  
Miscellaneous  -  PHP i18n 1.0.0a
PHP i18n is a PHP framework and function libraries to do internationalization (i18n) and localization of your PHP web sites.
40.96 KB  
Education  -  Touch Lua 1.3.1
Program with Lua, a simple and modern programming language. Luas syntax is simple as BASIC but Lua is faster and more powerful. Which make it just perfect for iPhone platform. *** TouchLua+ (iPad version of TouchLua) is now available at App...
2.6 MB  
Security Tools  -  CuteShield Internet Eraser Lite 2.0
Protects your privacy by cleaning up all the tracks of your Internet and computer activities (Free popup blocker included) The tool is integrated with IE and it can erase the browser cache, history, cookies, typed URLs, autocomplete list and so on...
Miscellaneous  -  PHP i18n .0a 1.0
PHP i18n is a PHP framework and function libraries to do internationalization (i18n) and localization of your PHP web sites.
Communication  -  HistConnect 1.0
This Function HistConnect will make a smooth histogram for a signal or image consisting of a few samples. The function assumes correlation between the samples, and implicitly generates new linear-interpolated samples between the originate samples....
10 KB  
Network & Internet  -  paralleltools 0.0.2
Parallel tools (named in manner to itertools & functools) is a set of commonly used list traversal functions, which is working in parallel (fault-tolerant) in synchronous or asynchronous manner. Implementation is based on python...
10.24 KB  
Music  -  ChoPlayer flat 1.1.2
A new music player corresponding to iOS7. List of functions ?I pursue a feeling of simple operation by the flick ?I read music aloud and function (the sound data are acquired than online) ?Making of the playlist independent of...
8.9 MB  
Programming  -  FLEX-db Digital Asset Manager 3.0.9
FLEX-db - an enterprise Digital Asset Manager (DAM). It ingests and links metadata with files, creates thumbnails, and processes files using business rules. FLEX-db has a JSP client, Java app server for file input and output and an EJB metadata...
21.57 MB  
Programming  -  Libicom 0.9.0
The libicom library is a character based dynamicly linked library for Linux. It is used to remotely control the Icom IC-R8500 wide band receiver via an RS232 link. All call and return parameters to the control functions are character string based....
20.48 KB  
Programming  -  dotdesktop 0.3
Dotdesktop library provides ability to parse desktop entry file and access the information in a convenient way. Desktop entry file format is defined by, it is used to describe information about an application such as the name and...
327.68 KB  
Programming  -  Cedalion for Linux 0.2.6
Cedalion is a programming language that allows its users to add new abstractions and define (and use) internal DSLs. Its innovation is in the fact that it uses projectional editing to allow the new abstractions to have no syntactic limitations.
471.04 KB  
Programming  -  libyasl 0.2
Libyasl is a C++ class library to easily realize TCP/UDP/Multicast clientsand servers in IPv4 and IPv6 environments under GNU/Linux systems.
143.36 KB  
Libraries  -  EuGTK 4.8.9
Makes it easy to develop good- looking, fast, cross-platform programs that run on Linux, OS X, and Windows. Euphoria is a very fast interpreted/compiled language with straight-forward syntax. EuGTK allows programming in a clean, object-oriented...
10.68 MB  
Libraries  -  Linux User Group Library Manager 1.0
The LUG Library Manager is a project to help Linux User Groups start their own library. A LUG library is helpful to the community at large because it increases access to information, and gives everyone the opportunity to become more knowledgeable.
5.35 KB  
Libraries  -  Module::MakefilePL::Parse 0.12
Module::MakefilePL::Parse is a Perl module to parse required modules from Makefile.PL. SYNOPSIS use Module::MakefilePL::Parse; open $fh, Makefile.PL; $parser = Module::MakefilePL::Parse->new( join("", ) ); $info = $parser->required;...
8.19 KB  
Libraries  -  sqlpp 0.06
sqlpp Perl package is a SQL preprocessor. sqlpp is a conventional cpp-alike preprocessor taught to understand SQL ( PgSQL, in particular) syntax specificities. In addition to the standard #define/#ifdef/#else/#endif cohort, provides also...
10.24 KB  
Libraries  -  App::SimpleScan::Substitution::Line 2.02
App::SimpleScan::Substitution::Line is a line with optional fixed variable values. SYNOPSIS my $line = App::SimpleScan::Substitution::Line->new(" this "); # Use only this value when substituting " ". $line->fix(substituite =>...
54.27 KB