5 ms·
Putting things in a map or set is almost invariably slower, often much slower, than a smart sort. If performance doesn't matter, then go ahead. Most often sort
by ncmncm 7y ago
Putting things in a map or set is almost invariably slower, often much slower, than a smart sort. If performance doesn't matter, then go ahead. Most often sort performance doesn't matter, or anyway most of the time is spent elsewhere. People do use Python or Bash in production, without shame.
But some of us work on problems where performance of the sort does matter.
- Ericson2314 7y agoSure, it is slower, but my point is not that I sort by doing `Map.toList . map.fromList` but that I don't immediately turn the map back to a list. The sorting literature is optimizing a thing I don't need to to do.
- ComputerGuru 7y agoJust because you’re not using it directly doesn’t mean that you’re not benefiting from those optimization in those layers you are depending on.
- Ericson2314 7y agoI'm not using it directly or indirectly. The whole point of this sorting literature is a space-time tradeoff that's completely different from when you want an ordered map/index as the end result.
- deleted 7y ago[deleted]
- Ono-Sendai 7y agoNot really true, putting things in a hash map is pretty fast, and generally faster than a comparison based sort.
- cozzyd 7y agoA hash map is unsorted so it's not a useful way to sort data
- Ericson2314 7y agoVery true. I like rich keys with non-trivial comparison cost. I even better like nested maps which no only are often useful in their own right, but also server to cache the cost of comparison wrt the original map---a domain-specific trie. Map are just far more the bread and butter of programming than sorting, and not just if you are using the one of the languages satirized by https://elbenshira.com/blog/the-universal-data-structure/ https://elbenshira.com/blog/the-universal-data-structure/