Reputation: 570
Could anyone explain what is faster for reading, writing in Ruby: an Array
or a Hash
? And what are the usecases for Array
and Hash
?
Array.new
Hash.new
Upvotes: 5
Views: 176
Reputation: 10018
If you need to store only some unique unordered values, please consider using Set.new
. It's convenient hash based class with writing and reading in constant time.
Upvotes: 3
Reputation: 118271
For reading and writing Hash.new
is faster than Array.new
. Watch this Why Hashes Will Be Faster in Ruby 2.0
.
Upvotes: 2