On Monday, July 18, 2011 9:12:05 AM UTC-6, Meikel Brandmeyer wrote:
>
> Hi,
>
> *snip*
>
> However with a different performance promise, I believe.
>

Hi Meikel,

I took a look at the source for subseq, and you're right.  To be specific, 
when the comparison operation is either > or >=, seqFrom allows subseq to 
get to the elements of interest in O(log n) steps, whereas drop-while needs 
O(n) steps to do the same.

On the other hand, it looks like when the elements of interest are at the 
beginning of the collection (using < or <= as comparison operation), subseq 
and take-while should perform the same, since subseq simply uses take-while 
to iterate through the elements of interest in this case.

To make a long story short, when using > or >=, use subseq instead of 
drop-while, especially if the elements of interest are deep in the 
collection or the same collection will be accessed multiple times.  When 
using < or <=, subseq and take-while should have the same performance.  Does 
that sound about right?

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