Hi, there. I have a question about the memoization in clojure.
I compare two functions to test the performance improvement of memoization:
(defn fib [n]
(if (or (zero? n) (= n 1))
1
(+ (fib (dec n) ) (fib (- n 2)))))
(time (fib 30))
get the result:
"Elapsed time: 316.65 msecs"
1346269
And then test for memoization:
user> (time ((memoize fib-nocur) 30))
"Elapsed time: 308.729 msecs"
1346269
user> (time ((memoize fib-nocur) 30))
"Elapsed time: 314.942 msecs"
1346269
user> (time ((memoize fib-nocur) 30))
"Elapsed time: 308.657 msecs"
1346269
Seems no effect. Since I just test it in nrepl and have no experience about
using clojure in project, I wander was the memoization really works?
Look forward to your responses
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.