On Dec 13, 10:41 am, Dmitri <dmitri.sotni...@gmail.com> wrote: > I wrote a simple word counter described herehttp://ptrace.fefe.de/wp/ > it reads stdin and counts the occurrences of words, however I notice > that it runs significantly slower than the java version in the link. > > I was wondering why there is such a dramatic difference. The approach > I took was to create a map keyed on words and use the occurrence count > as the value. When each line is read from input it's tokenized and the > word counts are updated. The slowdown seems to occur in the inc-count > function, where it "updates" the map using the assoc. Is this not a > proper way to approach this in clojure? > > I've also noticed that there is a significant speed difference between > conj and assoc, why is that? > If I understand correctly both should only create the delta of the new > elements and the old structure, however assoc appears to perform much > better. > It's doing that, but that is still less performant than a mutable map.
Another thing you can try doing is not reversing -- why not sort by (fn [x] (- (first x)) ? -- Michel --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---