2008/10/8 CuppoJava <[EMAIL PROTECTED]>:

> I'm very new to clojure, and I'm just wondering what's the most
> efficient way of creating a vector of zeroes.
...
> It looks pretty bad to me. My java code is more terse than this.
> Thanks for your help.

I would write something like this to create a vector of N zeroes:

(vec (map (fn [_] 0) (range N)))

but I had no idea whether it's fast or not. Thus, I compared this with
the solutions other people posted and ran each variant inside both
(time) and (doall), and repeated the runs 100 times to get an average.
Here are the results, with averaged time in milliseconds per one
evaluation:

33ms: (vec (map (fn [_] 0) (range 100000)))
48ms: (vec (replicate 100000 0))
56ms: (into [] (replicate 100000 0)))

I'm kind of surprised -- I'd expect map to cost more.

Further, I would be interested in profiling my Clojure code in order
to learn what's fast and what's slow. If anyone knows something better
than using (time) I'd appreciate telling me about it, please. Didn't
find anything apparent on Google. Would Java profilers be much help
wrt. Clojure?


br,
S

-- 
() Today is the car of the cdr of your life.
/\ http://arc.pasp.de/

--~--~---------~--~----~------------~-------~--~----~
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