3 ms·
Since the other comments are platitudes, I'll try to give some concrete information. Well implemented purely functional data structures are usually anywhere fro
by jules 13y ago
Since the other comments are platitudes, I'll try to give some concrete information. Well implemented purely functional data structures are usually anywhere from just as fast to about 20x slower. If the imperative version is tree like, the cost for lookups in the functional version is the same, but the cost for updating is a bit higher because a path needs to be copied rather than just 1 node modified in place. For a data structure like an unordered map, you can use a hash table backed by an array for the imperative version, but you'll have to use a tree for the purely functional one. This can cause about a 10x-20x slowdown.
For example in this post http://donsbot.wordpress.com/2009/09/26/very-fast-scalable-mutable-maps-and-hashes-for-haskell/ http://donsbot.wordpress.com/2009/09/26/very-fast-scalable-m... Haskell's Data.Map is compared with Judy arrays, and found to be 11x slower. Judy arrays themselves are about 2x slower than a basic hash table http://preshing.com/20130107/this-hash-table-is-faster-than-a-judy-array/ http://preshing.com/20130107/this-hash-table-is-faster-than-...
Is this slow? Perhaps, but in most cases the difference is smaller. Compare this to the speed of Ruby vs C, that can easily be a 100x difference yet people use Ruby a lot because of productivity reasons.
- dons 13y agoImportantly, comparing "ephemeral" structures - those that destroy previous states through direct hardware mutation - with persistent structures (such as all pure data structures) - is a fraught topic. You can surely gain speed ups on real hardware directly mutating memory you know to be reusable (linear) - but proving that precondition is very hard, and we often screw it up. Persistent data is a safe default. Mutation/destruction is an optimisation.