forked from Mirror/wren
hashBits() is used to generate a hash code from the same 64 bits used to represent a Wren number as a double. When building a map containing a large number of integer keys, it's important for this to do a good job scattering the bits across the 32-bit key space. Alas, it does not. Worse, the benchmark to test this happens to stop just before the performance falls off a cliff, so this was easy to overlook. This replaces it with the hash function V8 uses, which has much better performance across the numeric range.
20 lines
225 B
Ruby
20 lines
225 B
Ruby
start = Time.now
|
|
|
|
map = Hash.new
|
|
|
|
for i in (1..2000000)
|
|
map[i] = i
|
|
end
|
|
|
|
sum = 0
|
|
for i in (1..2000000)
|
|
sum = sum + map[i]
|
|
end
|
|
puts sum
|
|
|
|
for i in (1..2000000)
|
|
map.delete(i)
|
|
end
|
|
|
|
puts "elapsed: " + (Time.now - start).to_s
|