Skip to content

Instantly share code, notes, and snippets.

@nathell
Created May 28, 2010 20:16
Show Gist options
  • Save nathell/417669 to your computer and use it in GitHub Desktop.
Save nathell/417669 to your computer and use it in GitHub Desktop.

Revisions

  1. nathell created this gist May 28, 2010.
    20 changes: 20 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    (ns mmu
    (:gen-class)
    (:use [clojure.contrib duck-streams]))

    (defn gc []
    (dotimes [_ 4] (System/gc)))

    (defn used-memory []
    (let [runtime (Runtime/getRuntime)]
    (gc)
    (- (.totalMemory runtime) (.freeMemory runtime))))

    (defn measure [f]
    (let [before (used-memory)
    _ (def foo (with-in-reader f (read)))
    after (used-memory)]
    (- after before)))

    (defn -main [f]
    (println "Approximate memory usage:" (measure f)))