On Saturday 06 December 2008 17:11, Christian Vest Hansen wrote:
> I played around with some code, trying to explore the memory problems
> with 'filter' that is discussed in another thread, when I noticed an
> unexpected behavior from 'nth'.
>
> Behold:
>
> user=> (nth (repeatedly (fn [] 0)) 10000000)
> java.lang.OutOfMemoryError: Java heap space (NO_SOURCE_FILE:0)
> user=> (defn xth [coll i]
>   (if (zero? i) (first coll) (recur (rest coll) (dec i))))
> #'user/xth
> user=> (xth (repeatedly (fn [] 0)) 10000000)
> 0
>
> I could be wrong, but I don't think 'nth' should blow the heap here.

I cannot reproduce this while invoking Java with the default heap 
allocation.

Also:

user=> (time (nth (repeatedly (fn [] 0)) 10000000))
"Elapsed time: 7572.222 msecs"
0
user=> (time (nth (repeatedly (fn [] 0)) 10000000))
"Elapsed time: 7632.135 msecs"
0
user=> (time (nth (repeatedly (fn [] 0)) 10000000))
"Elapsed time: 7675.07 msecs"
0
user=> (time (nth (repeatedly (fn [] 0)) 10000000))
"Elapsed time: 2236.852 msecs"
0
user=> (time (nth (repeatedly (fn [] 0)) 10000000))
"Elapsed time: 2166.64 msecs"
0
user=> (time (nth (repeatedly (fn [] 0)) 10000000))
"Elapsed time: 2270.884 msecs"
0


user=> (time (xth (repeatedly (fn [] 0)) 10000000))
"Elapsed time: 3264.81 msecs"
0
user=> (time (xth (repeatedly (fn [] 0)) 10000000))
"Elapsed time: 3257.63 msecs"
0
user=> (time (xth (repeatedly (fn [] 0)) 10000000))
"Elapsed time: 3361.943 msecs"
0
user=> (time (xth (repeatedly (fn [] 0)) 10000000))
"Elapsed time: 3245.313 msecs"
0
user=> (time (xth (repeatedly (fn [] 0)) 10000000))
"Elapsed time: 3290.656 msecs"
0
user=> (time (xth (repeatedly (fn [] 0)) 10000000))
"Elapsed time: 3264.101 msecs"
0


These results were for a newly launched instance. I submitted the 
definition of (xth ...) between the two sequences of invocations shown 
above.


Randall Schulz

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to