On Wed, Dec 22, 2010 at 1:22 PM, Ken Wesson <kwess...@gmail.com> wrote:

>
> (defn count-num-chars [^String s]
>   (let [l (int (.length s))]
>    (loop [i (int 0) acc (int 0)]
>      (if (< i l)
>        (recur (unchecked-inc i) (if (= (.charAt s i) \space) acc
> (unchecked-inc acc)))
>        acc))))
>
> 15k nsec -- twice as fast as before. Still 5x slower than Java; I'm
> not sure why. This is now directly equivalent to the obvious Java
> implementation,
>

If you're on 1.2 performance will suffer from boxing/unboxing numbers as
well as vars being dynamically rebindable by default.

You should see a reasonable jump in perf for the same code on the latest 1.3
alphas. You can also remove all those 'int' type-hints.

David

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