Hi all, I am wondering is there a way we can measure the memory consumption of a program in Clojure.
Let’s say this is an algorithm for finding the Levenshtein Distance
(defn cost [a b]
(if (= a b) 0 1))
(defn levenshtein-distance
"Calculates the edit-distance between two sequences"
[seq1 seq2]
(cond
(empty? seq1) (count seq2)
(empty? seq2) (count seq1)
:else (min
(+ (cost (first seq1) (first seq2)) (levenshtein-distance (rest seq1) (rest seq2))) ;; substitution
(inc (levenshtein-distance (rest seq1) seq2)) ;; insertion
(inc (levenshtein-distance seq1 (rest seq2)))))) ;; deletion
This works:
user> (levenshtein-distance "kitten" "sitting")
3
How to know how much memory this function (levenshtein-distance) has consumed? Thanks in advance.