Fix the 'real' bench to make it real for real
This commit is contained in:
+23
-22
@@ -1,54 +1,55 @@
|
||||
import { Bench } from "tinybench";
|
||||
import { type Box, box } from "./../engine/lib/box.ts";
|
||||
import { createDictionary, forEntry } from "./../engine/lib/Dictionary.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: 1000 });
|
||||
const bench = new Bench({ name: "MapArray get", time: 3000 });
|
||||
let sink = 0;
|
||||
|
||||
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 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 get reads", () => {
|
||||
.add("MapArray iter/get reads", () => {
|
||||
let sum = 0;
|
||||
|
||||
for (const [key] of ma.entries()) {
|
||||
sum += ma.get(key)!.value;
|
||||
}
|
||||
|
||||
void sum;
|
||||
sink += sum;
|
||||
})
|
||||
.add("Dictionary get reads", () => {
|
||||
.add("Dictionary iter/get reads", () => {
|
||||
let sum = 0;
|
||||
|
||||
forEntry(dict, (box) => {
|
||||
sum += box.value;
|
||||
forEntry(dict, (_, key) => {
|
||||
sum += getEntry(dict, key)!.value;
|
||||
});
|
||||
|
||||
void sum;
|
||||
sink += sum;
|
||||
})
|
||||
.add("Map get reads", () => {
|
||||
.add("Map iter/get reads", () => {
|
||||
let sum = 0;
|
||||
|
||||
for (const [key] of ma.entries()) {
|
||||
for (const [key] of map.entries()) {
|
||||
sum += map.get(key)!.value;
|
||||
}
|
||||
|
||||
void sum;
|
||||
sink += sum;
|
||||
});
|
||||
|
||||
await bench.run();
|
||||
|
||||
console.log("sink (ignore):", sink);
|
||||
console.table(bench.table());
|
||||
|
||||
Reference in New Issue
Block a user