This is interesting. We can get quite a huge performance boos by type 
hinting that impl.

Times on my system running Clojure 1.4.0:

user=> (defn s-blank? [s] (every? #(Character/isWhitespace %) s))
user=> (time (dotimes [n 20000] (s-blank? "asdf")))
"Elapsed time: 247.252 msecs"

Now if we type hint s-blank, here's what I get:

(defn s-blank? [^CharSequence s] (every? (fn [^Character c] 
(Character/isWhitespace c)) s))

user=> (time (dotimes [n 20000] (s-blank? "asdf")))
"Elapsed time: 9.122 msecs"

Not bad :) Especially when compared to clojure's blank? :

user=> (time (dotimes [n 20000] (clojure.string/blank? "asdf")))
"Elapsed time: 2.62 msecs"

Is it still slower? Absolutely! But we didn't have to give up the 
functional approach to boost performance - a little type hinting in this 
case provided a huge benefit.

On Wednesday, January 16, 2013 7:35:07 AM UTC+11, Thomas wrote:
>
> I think I just answered my own question...
>
> user=> (time (dotimes [n 20000] (s-blank? "asdf")))
> "Elapsed time: 2481.018 msecs"
> nil
> user=> (time (dotimes [n 20000] (blank? "asdf")))
> "Elapsed time: 14.347 msecs"
> nil
> user=> 
>
> Quite a difference I have to say. 
>
> Thomas
>

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