Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
谁能解释一下用 Ruby 读、写什么更快:anArray还是 a Hash?和 的用例是Array什么Hash?
Array
Hash
Array.new Hash.new
如果您只需要存储一些唯一的无序值,请考虑使用Set.new. 这是一个方便的基于哈希的类,可以在恒定时间内写入和读取。
Set.new
因为读写Hash.new速度比Array.new. 看这个Why Hashes Will Be Faster in Ruby 2.0。
Hash.new
Array.new
Why Hashes Will Be Faster in Ruby 2.0