Note that the two functions aren't actually equivalent, since the
blank? that uses every? will accept anything that can be made a seq,
while the blank? in clojure.string does not.

Given an annotation like this, and assuming that every? is clojure.core/every?

(defn blank? [^CharSequence s] (every? #(Character/isWhitespace %) s))

it seems as if it should be possible for the compiler to generate the
faster code.

On Tue, Jan 15, 2013 at 12:42 PM, Marko Topolnik
<[email protected]> wrote:
>
>
> On Tuesday, January 15, 2013 9:35:07 PM UTC+1, 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.
>
>
> Yes; moreover, I find it misleading and almost a case of false advertising
> when such succint code is demonstrated without so much as a footnote
> mentioning the enormous performance penalty of converting a String into a
> sequence of Characters and then calling a higher-order function on it. The
> proper way to advertise Clojure is this: in Java you have little choice but
> write verbose, performant code; in Clojure you can go both ways and for most
> cases the overhead won't be the main bottleneck. But, at all times, do keep
> in mind the consequences of your choice of idiom.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en



-- 
Ben Wolfson
"Human kind has used its intelligence to vary the flavour of drinks,
which may be sweet, aromatic, fermented or spirit-based. ... Family
and social life also offer numerous other occasions to consume drinks
for pleasure." [Larousse, "Drink" entry]

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to