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.
(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)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment