Skip to content

Instantly share code, notes, and snippets.

@tizoc
Created November 30, 2011 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tizoc/1408779 to your computer and use it in GitHub Desktop.
Save tizoc/1408779 to your computer and use it in GitHub Desktop.
> clj
Clojure 1.3.0
user=> (def rands (repeatedly rand))
#'user/rands
user=> (def ^doubles tmp (take 300000 rands))
#'user/tmp
user=> (time (reduce + tmp))
"Elapsed time: 433.227 msecs"
149973.6787182885
user=> (time (reduce + tmp))
"Elapsed time: 36.465 msecs"
149973.6787182885
user=> (time (reduce + tmp))
"Elapsed time: 30.094 msecs"
149973.6787182885
user=> (time (reduce + tmp))
"Elapsed time: 13.557 msecs"
149973.6787182885
user=> (time (reduce + tmp))
"Elapsed time: 13.408 msecs"
149973.6787182885
user=> (def tmp2 (double-array tmp))
#'user/tmp2
user=> (time (reduce + tmp2))
"Elapsed time: 15.851 msecs"
149973.6787182885
user=> (time (reduce + tmp2))
"Elapsed time: 6.072 msecs"
149973.6787182885
user=> (time (reduce + tmp2))
"Elapsed time: 2.824 msecs"
149973.6787182885
user=> (time (reduce + tmp2))
"Elapsed time: 3.009 msecs"
149973.6787182885
user=> (def tmp3 (double-array 3000000 rands))
OutOfMemoryError Java heap space clojure.core/repeatedly (core.clj:4512)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment