Re: Performance tips for Clojure

2009-03-14 Thread Stu Hood
There is a interface 'Counted' that a lot of Clojure data structures implement to indicate that they provide O(1) for (count). Thanks, Stu On Fri, Mar 13, 2009 at 4:59 AM, Christophe Grand wrote: > > Christian Vest Hansen a écrit : > > I think that count is O(n) for lists, no? > > > > Count is O

Re: Performance tips for Clojure

2009-03-13 Thread Christophe Grand
Christian Vest Hansen a écrit : > I think that count is O(n) for lists, no? > Count is O(1) for lists but O(n) for a chain of conses. Clojure user=> (let [l (apply list (range 10))] (time (dotimes [_ 100] (count l "Elapsed time: 169.710116 msecs" nil user=> (let [l (apply list (r

Re: Performance tips for Clojure

2009-03-13 Thread Christian Vest Hansen
On Fri, Mar 13, 2009 at 7:49 AM, Chouser wrote: > > On Fri, Mar 13, 2009 at 2:18 AM, Sergio wrote: >> >> There are a couple of obvious ones, but also some others that I >> haven't seen documented (like, map is much faster on lists than on >> vectors since rest is O(1) for lists). > > You're righ

Re: Performance tips for Clojure

2009-03-13 Thread Mark Engelberg
list doesn't do what you think it does. You've just created a list of one element. On Fri, Mar 13, 2009 at 12:10 AM, Sergio wrote: > (def ls (list (range 100))) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups

Re: Performance tips for Clojure

2009-03-13 Thread Sergio
Sorry =( I am horribly mistaken I should have taken my time before posting.. But still, I really thought cons on vectors was O(n) base on PersistentVector.java, line 148 (The version I'm reading is not the current SVN head, so I don't know if it is that line for you) Here is the snippet:

Re: Performance tips for Clojure

2009-03-12 Thread Chouser
On Fri, Mar 13, 2009 at 2:18 AM, Sergio wrote: > > There are a couple of obvious ones, but also some others that I > haven't seen documented (like, map is much faster on lists than on > vectors since rest is O(1) for lists). You're right that 'rest' is O(1) for lists, but it's O(1) for vectors a