The difference is not HUGE, but in a critical section it might be a
valid micro-optimization. I'd also be interested to know why, but I
bet you're assumption of apply being thrown in the mix is probably
pretty close to true.

user=> (time (dotimes [_ 1e6] (doall (map #(filter even? %) (for [i
(range 0 100 4)] (range i (+ i 4)))))))
"Elapsed time: 6589.49 msecs"
nil
user=> (time (dotimes [_ 1e6] (doall (map #(filter even? %) (for [i
(range 0 100 4)] (range i (+ i 4)))))))
"Elapsed time: 6620.396 msecs"
nil
user=> (time (dotimes [_ 1e6] (doall (map (partial filter even?) (for
[i (range 0 100 4)] (range i (+ i 4)))))))
"Elapsed time: 8899.466 msecs"
nil
user=> (time (dotimes [_ 1e6] (doall (map (partial filter even?) (for
[i (range 0 100 4)] (range i (+ i 4)))))))
"Elapsed time: 8949.646 msecs"
nil

(sorry for further hijacking the thread)




On Aug 23, 6:09 pm, Alan <a...@malloys.org> wrote:
> Really? I would be interested to hear why; is it maybe because partial
> has to take any number of arguments and then (apply even? args)?
>
> I've taken to using partial when I can, precisely because of the
> difficulty of nesting anonymous functions, and while performance isn't
> a big deal for me I'm curious.
>
> On Aug 23, 12:30 pm, Cameron <cpuls...@gmail.com> wrote:
>
>
>
> > Again with the bad examples but...
>
> > (map #(even? %) coll) is faster than
> > (map (partial even?) coll)
>
> > So it's at least got that going for it.
>
> > (I know this SHOULD be written as (map even? coll))
>
> > On Aug 23, 1:59 pm, Michael Gardner <gardne...@gmail.com> wrote:
>
> > > On Aug 23, 2010, at 11:13 AM, Luka Stojanovic wrote:
>
> > > > On Mon, 23 Aug 2010 18:01:13 +0200, Joop Kiefte <iko...@gmail.com> 
> > > > wrote:
>
> > > >> bad example =/
>
> > > >> Yes, it is
>
> > > >> but you get the gist I hope
>
> > > >> better example: #(first (sort %)) ;)
>
> > > > (comp first sort)
>
> > > > and #(some-fn x %) can be written as
> > > > (partial some-fn x)
>
> > > > which leaves #(some-fn % x) as case not trivial with other syntax
>
> > > > again (fn [y] (some-fn y x)) is about 8 chars longer, so I guess #() 
> > > > form really is not something that should be used that often
>
> > > I don't know about you, but I find #(= 2 (count %)) much nicer and easier 
> > > to read than (comp (partial = 2) count).

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