And here are some numbers from my machine:
(def my-list (list 'a 'b 'c 'd 'e 'f 'g 'h 'i 'j))
(def my-vector ['a 'b 'c 'd 'e 'f 'g 'h 'i 'j])

; ~44ms
(time (dotimes [x 1000000]
(conj my-list 'k)))

; ~26ms
(time (dotimes [x 1000000]
(pop my-list)))

; ~100ms
(time (dotimes [x 1000000]
(conj my-vector 'k)))

; ~100ms
(time (dotimes [x 1000000]
(pop my-vector)))

Clojure makes it very easy to see what's going on, the REPL is your friend
;)


On Fri, May 15, 2009 at 4:07 PM, tmountain <tinymount...@gmail.com> wrote:

>
> I'm no expert, but I think this explain some:
>
> Clojure's conj function is like Lisp's cons, but "does the right
> thing", depending on the data type.  It is fast to add something to
> the front of the list, and slower to add something to the end.
> Vectors are the opposite, you can add to the end fast, slower to add
> to the front.  This isn't specific to Clojure, it's just the way those
> data structures work in any language.  So conj adds the item to the
> front if it is conjing on a list, to the end if is conjing on a
> vector.  This is part of how clojure provides a unified method of
> handling different type of data structures, which are collectively
> called sequences in Clojure.
>
> Excerpted from here:
>
>
> http://groups.google.com/group/novalanguages/browse_thread/thread/bcb78a59382227e0
>
> It's also worth noting that lists are the canonical datatype in Lisp,
> so they're probably kept around for that reason as well.
>
> Travis
>
> Clojure's conj function is like Lisp's cons, but "does the right
> thing", depending on
> the data type.  It is fast to add something to the front of the list,
> and slower to add something to the end.  Vectors are the opposite, you
> can add to the end fast, slower to add to the front.  This isn't
> specific to Clojure, it's just the way those data structures work in
> any language.  So conj adds the item to the front if it is conjing on
> a list, to the end if is conjing on a vector.  This is part of how
> clojure provides a unified method of handling different type of data
> structures, which are collectively called sequences in Clojure.
>
> On May 15, 3:36 pm, Vagif Verdi <vagif.ve...@gmail.com> wrote:
> > What are the use case scenarios where one is preferable to the other
> > in clojure ?
> >
> > It looks to me like vectors almost completely overtake lists for all
> > purposes.
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to