On Oct 15, 1:07 pm, "Jim - FooBar();" <jimpil1...@gmail.com> wrote:
> On 15/10/12 19:42, Ben Smith-Mannschott wrote:
>
> > If the distinction I'm trying to make is not clear to you, I'd suggest
> > having a look athttp://www.infoq.com/presentations/Clojure-Macros (It
> > does a good job exploring these kinds of distinctions as it's vital to
> > have an accurate mental model of how Clojure is evaluated if one
> > intends to write macros.)
>
> after watching this talk I tried this at a repl:
>
> (defmacro plus
> "Perform addition at compile time."
>   [numbers]
>    (apply + (eval numbers)))
>
> user=> (time (plus (vec (range 10000))))
> "Elapsed time: 0.015635 msecs" ;;WOW
> 49995000
>
> user=> (time (apply + (vec (range 10000))))
> "Elapsed time: 16.732054 msecs" ;;160 times slower
> 49995000
>
> before jumping to any conclusions (and rushing to change some of my
> code) would you say timing is realistic? Is it expected to see such a
> dramatic speed increase? To be honest I'm a bit surprised...Regardless
> of when the actual calculation will be performed (compile vs run time),
> it will eventually be performed. why is at compile time so much faster?

You add the numbers at compile time, and then time how long it takes
to...do nothing to them, at runtime. You are comparing N to zero, not
to some smaller factor of N.

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