That explains the good performance. Either way, the implementation is quite a 
bit clearer.

I've also compared some operations of sparse-vec vs. plain map. 
The inner product is slightly faster for vecs with < 100000 elements, then map 
takes over.
norm and unit-vector operations are quite in favour of sparse-vecs (~ 4 times 
faster than map based implementations).

Obviously, assoc on a map is way faster than the sparse-vec implementation of 
assc below...

Kind Regards
Andreas


On 27/05/2011, at 11:11 AM, Ken Wesson wrote:

> On Thu, May 26, 2011 at 8:50 PM, Andreas Kostler
> <andreas.koestler.le...@gmail.com> wrote:
>> Thanks Ken,
>> using this approach brings a ~1000 times speedup :)
>> 
>> (def a (sparse-vec (range 100000) (range 100000)))
>> 
>> (def b (time (assc-ken a 111111 0)))
>> "Elapsed time: 0.249 msecs"
>> 
>> (def b (time (assc a 111111 0)))
>> "Elapsed time: 252.06 msecs"
>> 
>> Very worthwhile and it's clearer as well.
> 
> You're welcome. Keep in mind that this is a best-case insert, right at
> the end, for the algo I posted. Inserts at the beginning won't be very
> much faster than before, and in the middle will be in the middle.
> 
> -- 
> Protege: What is this seething mass of parentheses?!
> Master: Your father's Lisp REPL. This is the language of a true
> hacker. Not as clumsy or random as C++; a language for a more
> civilized age.
> 
> -- 
> 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

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