On Wed, Apr 25, 2012 at 10:30 AM, Shantanu Kumar
<[email protected]> wrote:
> user=> (let [x (Foo. 10 20)] (time (Bar. (:a x) (:b x) 30)))
> "Elapsed time: 0.686 msecs"
> #user.Bar{:a 10, :b 20, :c 30}
>
> Whereas, doing the same with a map is very cheap:
>
> user=> (let [x {:a 10 :b 20}] (time (assoc x :c 30)))
> "Elapsed time: 0.05 msecs"
> {:c 30, :a 10, :b 20}
With Clojure 1.3 (lein repl in a project) I get the following results:
user=> (time (dotimes [_ 10000000] (let [x (Foo. 10 20)] (Bar. (:a
x) (:b x) 30))))
"Elapsed time: 739.961923 msecs"
nil
and
user=> (time (dotimes [_ 10000000] (let [x {:a 10 :b 20}] (assoc x :c 30))))
"Elapsed time: 2496.002425 msecs"
nil
Timing for a single assigment without looping is bound to have some
variance that does not reflect real performance.
Regards,
Lars Nilsson
--
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