Another problem with (def fib (memoize ...)) for tight recursion patterns
with little code is the cost of accessing the var itself, which may also
prevent further optimizations. To restrict the scope of memoization and
obtain both simplicity and even more efficiency:
(letfn [(fib [x]
On Sunday, April 14, 2013 5:30:13 PM UTC+1, Jonathan Fischer Friberg wrote:
Calling fib just creates a new function, no values
are calculated. So you're measuring the time
it takes to create a function, and not the calculation
of fibonacci numbers.
Oops ;)
Of course you are right. The
And in cases like this recursive function, not only you need to do as above
said, but also you will want to make sure that the recursive calls use the
memoized function, otherwise, only top level results are getting the
benefit of memoization, resulting in the same tragic exponential time
Hi all,
I have been looking into the PersistentVector implementation, and I came up
with a simple improvement relevant for small vectors, of between 33 and 64
elements. For these sizes I found an assoc loop to be between 29% and 39%
faster and a get loop between 4% and 8% faster. The memory