On Mon, Feb 4, 2013 at 12:13 PM, Paul Stadig <p...@stadig.name> wrote:

> On Sunday, February 3, 2013 9:56:49 PM UTC-5, puzzler wrote:
>>
>> In these examples, the map/record is freshly created each time through
>> the loop, so caching should not be a factor.
>>
>
> Good point. So maybe it's not the caching :).
>
> Another factor is that literal hashmaps are actually PersistentArrayMaps.
> If you use PersistentHashMaps instead of PersistentArrayMaps you get
> similar performance:
>
> Clojure 1.5.0-RC4
> user=> (class {:x "a" :y 3})
> clojure.lang.PersistentArrayMap
>
well that explains why there's more time in this sample:
=> (class {:x "a" :y 3})
clojure.lang.Persistent*Array*Map
=> (def m {:x "a" :y 3})
#'runtime.q/m
=> (class m)
clojure.lang.Persistent*Hash*Map
=> (time (dotimes [n 10000000] (hash m)))
"Elapsed time: 168.162927 msecs"
nil
=> (time (dotimes [n 10000000] (hash m)))
"Elapsed time: 161.341094 msecs"
nil
=> (time (dotimes [n 10000000] (hash m)))
"Elapsed time: 159.444025 msecs"
nil
=> (time (dotimes [n 10000000] (hash {:x "a" :y 3})))
"Elapsed time: 54.29475 msecs"
nil
=> (time (dotimes [n 10000000] (hash {:x "a" :y 3})))
"Elapsed time: 68.322372 msecs"
nil
=> (time (dotimes [n 10000000] (hash {:x "a" :y 3})))
"Elapsed time: 57.707132 msecs"
nil


> user=> (time (dotimes [n 10000000] (hash (hash-map :x "a" :y 3))))
> "Elapsed time: 3315.031872 msecs"
> nil
>
> => (time (dotimes [n 10000000] (hash (hash-map :x "a" :y 3))))
"Elapsed time: 8495.188813 msecs"
=> (def hm (hash-map :x "a" :y 3))
#'runtime.q/hm
=> (time (dotimes [n 10000000] (hash hm)))
"Elapsed time: 155.623505 msecs"
nil
=> (time (dotimes [n 10000000] (hash hm)))
"Elapsed time: 160.494044 msecs"
nil


>
> Paul
>
> --
> --
> 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
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Please correct me if I'm wrong or incomplete,
even if you think I'll subconsciously hate it.

-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to