![]() This lacks concrete numbers and is a purely theoretical analysis. The operation is linear, that is it takes time proportional to the collection size. The operation takes time proportional to the logarithm of the collection size. Some invocations of the operation might take longer, but if many operations are performed on average only constant time per operation is taken. The operation takes amortized constant time. The operation takes effectively constant time, but this might depend on some assumptions such as maximum length of a vector or distribution of hash keys. The operation takes (fast) constant time. The closest thing that's currently available describing the runtime characteristics of Scala collections is the table below, available on : operation ![]() ![]() foreach call? How does using Maps and Sets fit into all this? There is a lot of "common knowledge" around these: that Lists has a fast prepend but slow indexing, how Vectors are a "good general purpose collection", but surprisingly little concrete data around how these collections actually perform, in practice.įor example, how much more memory does a Vector take than an Array? How about a List? How much faster is iterating using a while-loop instead of a. The Scala programming language has a rich set of built-in collections: Lists, Vectors, Arrays, Sets, Maps, and so on. Performance Data with Standard Deviations.If you enjoyed the contents on this blog, you may also enjoy Haoyi's book Hands-on Scala Programming While a lot has been written about the Scala collections from an implementation point of view ( inheritance hierarchies, CanBuildFrom, etc.) surprisingly little has been written about how these collections actually behave under use.Īre Lists faster than Vectors for what you're doing, or are Vectors faster than Lists? How much memory can you save by using un-boxed Arrays to store primitives? When you do performance tricks like pre-allocating arrays or using a while-loop instead of a foreach call, how much does it really matter? var l: List or val b: mutable.Buffer? This post will tell you the answers.Ībout the Author: Haoyi is a software engineer, and the author of many open-source Scala tools such as the Ammonite REPL and the Mill Build Tool. This post will dive into the runtime characteristics of the Scala collections library, from an empirical point of view. Easy Parsing with Parser Combinators Old Design Patterns in Scala
0 Comments
Leave a Reply. |