Jonathan showed destructuring/indexing very nicely. Here are some
timings for vector/list creation:

(let [lst '(1 2 3)]
  (timings 1e7
    (list 1 2 3)
    (cons 1 (cons 2 (cons 3 ())))
    (conj (conj (conj () 3) 2) 1)

    (vector 1 2 3)
    (vec lst)
    (conj (conj (conj [] 1) 2) 3)))

 6590.33 ms   61.2%   1.6x  (list 1 2 3)
 7571.30 ms   70.3%   1.4x  (cons 1 (cons 2 (cons 3 ())))
 7773.67 ms   72.2%   1.4x  (conj (conj (conj () 3) 2) 1)
 9601.74 ms   89.1%   1.1x  (vector 1 2 3)
 8612.29 ms   79.9%   1.3x  (vec lst)
10772.88 ms  100.0%   1.0x  (conj (conj (conj [] 1) 2) 3)

Yes, it looks that list creation is faster than vector creation.

Frantisek

On Jul 9, 12:17 am, John Harrop <jharrop...@gmail.com> wrote:
> On Wed, Jul 8, 2009 at 4:57 PM, Frantisek Sodomka <fsodo...@gmail.com>wrote:
>
> > So far it seems that vectors win in Clojure:
>
> > (timings 3e5
> >  (let [v (vector 1 2 3) a (nth v 0) b (nth v 1) c (nth v 2)] (+ a b
> > c))
> >  (let [lst (list 1 2 3) a (nth lst 0) b (nth lst 1) c (nth lst 2)] (+
> > a b c)))
>
> > =>
> >  680.63 ms   83.6%   1.2x  (let [v (vector 1 2 3) a (nth v 0) b (nth
> > v 1) c (nth v 2)] (+ a b c))
> >  813.79 ms  100.0%   1.0x  (let [lst (list 1 2 3) a (nth lst 0) b
> > (nth lst 1) c (nth lst 2)] (+ a b c))
>
> Does using vec instead of vector make a difference? Using first, rest,
> first, rest instead of nth to destructure the list?
--~--~---------~--~----~------------~-------~--~----~
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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to