mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 06:08:41 +01:00
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.
25 lines
487 B
Plaintext
25 lines
487 B
Plaintext
// Skipping this for now because it is >10x slower than the other languages (!)
|
|
// and makes the benchmark running annoyingly slow.
|
|
main() {
|
|
Stopwatch watch = new Stopwatch();
|
|
watch.start();
|
|
|
|
var map = {};
|
|
|
|
for (var i = 1; i <= 2000000; i++) {
|
|
map[i] = i;
|
|
}
|
|
|
|
var sum = 0;
|
|
for (var i = 1; i <= 2000000; i++) {
|
|
sum += map[i];
|
|
}
|
|
print(sum);
|
|
|
|
for (var i = 1; i <= 2000000; i++) {
|
|
map.remove(i);
|
|
}
|
|
|
|
print("elapsed: ${watch.elapsedMilliseconds / 1000}");
|
|
}
|