What's better (faster? more memory efficient?) whe...
# codereview
m
What's better (faster? more memory efficient?) when creating mutable maps where the insertion order doesn't matter? Use
mutableMapOf()
and
toMutableMap()
which use
LinkedHashMap
or instead
hashMapOf()
and
HashMap(other)
?
g
hashMap
m
👍 thanks I guess maintaining the order adds quite noticeable overhead?
g
Not sure about real performance difference. you may try to find benchmarks. Also it depends on your use case
👌 1
LinkedHashMap consumes more memory because Entry has also
before
and
after
nodes
u
TreeMap maintains order
m
No, it's sorts entries :)
u
well yea, because its a sorted tree inside
thats why its log n
oh you asked order doesnt matter, sorry
m
But thanks for the intent :)