Reputation: 1832
I have a hash map, using string as key, values are list of strings of size 2. I am trying to get the fastest performance time when getting the values back. The values will always contain only 2 strings. The question are:
By the way, I couldn't find anything on Scala tuple's performance. Please share if you know of any.
Upvotes: 0
Views: 1549
Reputation: 4378
If you have a Tuple of two things, you will be using the case class Tuple2. As you can see, it is just a class that takes two parameters to instantiate.
If you're concerned about the performance of Lists versus Tuples, I suggest you write a benchmark. I find using ScalaMeter exceedingly useful when doing that. I suspect the performance of both will be the same.
If you're concerned about readability and reasonability of your code, I would suggest using a Tuple. If the values will always contain two values, then using Tuple2 is the better choice. Using a List implies that it could potentially contain less, or more, than two.
Upvotes: 6