Thanks Steve,
> returns a PersistentArrayMap if there are 8 entries or fewer and a
> PersistentHashMap otherwise.
Ah that makes sense. Thanks for the explination.
"The two (swap! a inc) forms are added to the map at read-time -
which
is before they are evaluated."
What's the reason for this? Is it because {} is a special form and so
behaves similar to a macro instead of a function in terms of argument
evaluation?
user=> (let [a (atom 0)] (hash-map (swap! a inc) 1 (swap! a inc) 2 3 3
4 4 5 5 6 6 7 7 8 8 9 9))
{1 1, 2 2, 3 3, 4 4, 5 5, 6 6, 7 7, 8 8, 9 9}
Is the reason for the different evaluation order performance related
for maps?
user=> (time (dotimes [i 1000000] {i :fun}))
"Elapsed time: 123.648676 msecs"
user=> (time (dotimes [i 1000000] (hash-map i :fun)))
"Elapsed time: 517.765247 msecs"
user=> (time (dotimes [i 1000000] (array-map i :fun)))
"Elapsed time: 414.936815 msecs"
Certainly seems to be faster to use {} than hash-map so I'm thinking
it must be related.
Regards,
Tim.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---