remove unnecessary data structs Dict+MapArray

This commit is contained in:
Schluffe
2026-08-27 23:43:28 +02:00
parent 2f7957b28a
commit 7b3c9865fe
10 changed files with 12 additions and 466 deletions
+4 -46
View File
@@ -1,53 +1,11 @@
import { Bench } from "tinybench";
import { type Box, box } from "./../engine/lib/box.ts";
import {
createDictionary,
forEntry,
getEntry,
} from "./../engine/lib/Dictionary.ts";
import MapArray from "./../engine/lib/MapArray.ts";
const bench = new Bench({ name: "MapArray get", time: 3000 });
const bench = new Bench({ name: "", time: 1000 });
let sink = 0;
const testData: Array<[string, Box<number>]> = [];
let i = 999;
while (i-- > 0) {
testData.push([String(i), box(i)]);
}
const ma = new MapArray(structuredClone(testData));
const dict = createDictionary(structuredClone(testData));
const map = new Map(structuredClone(testData));
bench
.add("MapArray iter/get reads", () => {
let sum = 0;
for (const [key] of ma.entries()) {
sum += ma.get(key)!.value;
}
sink += sum;
})
.add("Dictionary iter/get reads", () => {
let sum = 0;
forEntry(dict, (_, key) => {
sum += getEntry(dict, key)!.value;
});
sink += sum;
})
.add("Map iter/get reads", () => {
let sum = 0;
for (const [key] of map.entries()) {
sum += map.get(key)!.value;
}
sink += sum;
});
bench.add("", () => {
sink += 1;
});
await bench.run();