Add a real bench
This commit is contained in:
+45
-5
@@ -1,13 +1,53 @@
|
|||||||
import { Bench } from "tinybench";
|
import { Bench } from "tinybench";
|
||||||
|
import { type Box, box } from "./../engine/lib/box.ts";
|
||||||
|
import { createDictionary, forEntry } from "./../engine/lib/Dictionary.ts";
|
||||||
|
import MapArray from "./../engine/lib/MapArray.ts";
|
||||||
|
|
||||||
const bench = new Bench({ name: "MapArray get", time: 300 });
|
const bench = new Bench({ name: "MapArray get", time: 1000 });
|
||||||
|
|
||||||
|
const testData: Array<[string, Box<number>]> = [
|
||||||
|
["foo", box(1)],
|
||||||
|
["bar", box(2)],
|
||||||
|
["lol", box(3)],
|
||||||
|
["bob", box(4)],
|
||||||
|
["zig", box(5)],
|
||||||
|
["fuzz", box(6)],
|
||||||
|
["buss", box(7)],
|
||||||
|
["grep", box(8)],
|
||||||
|
["zeap", box(9)],
|
||||||
|
];
|
||||||
|
|
||||||
|
const ma = new MapArray(structuredClone(testData));
|
||||||
|
const dict = createDictionary(structuredClone(testData));
|
||||||
|
const map = new Map(structuredClone(testData));
|
||||||
|
|
||||||
bench
|
bench
|
||||||
.add("foo", () => {
|
.add("MapArray get reads", () => {
|
||||||
console.log("foo");
|
let sum = 0;
|
||||||
|
|
||||||
|
for (const [key] of ma.entries()) {
|
||||||
|
sum += ma.get(key)!.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sum;
|
||||||
})
|
})
|
||||||
.add("bar", () => {
|
.add("Dictionary get reads", () => {
|
||||||
console.log("bar");
|
let sum = 0;
|
||||||
|
|
||||||
|
forEntry(dict, (box) => {
|
||||||
|
sum += box.value;
|
||||||
|
});
|
||||||
|
|
||||||
|
void sum;
|
||||||
|
})
|
||||||
|
.add("Map get reads", () => {
|
||||||
|
let sum = 0;
|
||||||
|
|
||||||
|
for (const [key] of ma.entries()) {
|
||||||
|
sum += map.get(key)!.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sum;
|
||||||
});
|
});
|
||||||
|
|
||||||
await bench.run();
|
await bench.run();
|
||||||
|
|||||||
Reference in New Issue
Block a user