Re: Memoization in clojure

2013-04-14 Thread Paulo Sérgio Almeida
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]

Re: Memoization in clojure

2013-04-14 Thread Paulo Sérgio Almeida
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

Re: Memoization in clojure

2013-04-13 Thread Paulo Sérgio Almeida
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

An improvement to PersistentVector

2012-12-04 Thread Paulo Sérgio Almeida
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