Repository navigation
Expand file tree
/
Copy pathprofile.test.js
More file actions
72 lines (64 loc) · 3.99 KB
/
Copy pathprofile.test.js
File metadata and controls
72 lines (64 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import assert from "node:assert/strict";
import {readFileSync} from "node:fs";
import {test} from "node:test";
import {buildProfile} from "../docs/components/profile.js";
const description = (dataset, extra = {}) => ({benchmark: "A", generator: "g", dataset, dense: "true", ...extra});
const result = (dataset, framework, value, extra = {}) => ({
...description(dataset), framework, metric: "time", value, ...extra
});
test("ratios are sorted, failures stay in the denominator, and duplicates use their median", () => {
const profile = buildProfile([
result("one", "a", "4"), result("one", "a", "8"), result("one", "b", "2"),
result("two", "a", "1"), result("two", "b", "3")
], [description("one"), description("two"), description("failed")]);
assert.equal(profile.problems.length, 3);
assert.deepEqual(profile.series, {a: [[1, 1], [0, 3]], b: [[0, 1], [1, 3]]});
assert.deepEqual(profile.problems[0].tags, ["dense"]);
});
test("invalid values and other metrics cannot produce runtime successes", () => {
const rows = [null, "", "NaN", "Infinity", "0", "-1", true].map((value) => result("one", "a", value));
rows.push(result("one", "a", "1", {metric: "memory"}));
const profile = buildProfile(rows, [description("one")], ["a", "b"]);
assert.deepEqual(profile.series, {a: [], b: []});
assert.equal(profile.problems.length, 1);
assert.equal(profile.xMax, 2);
});
test("an all-failed run retains its frameworks and problems", () => {
const profile = buildProfile([], [description("one"), description("two")], ["a", "b"]);
assert.equal(profile.problems.length, 2);
assert.deepEqual(profile.series, {a: [], b: []});
assert.equal(profile.xMax, 2);
});
test("dataset identities include generator and preserve numeric-looking names", () => {
const descriptions = [description("01"), description("1"), description("1", {generator: "other"})];
const rows = descriptions.map((row) => result(row.dataset, "a", "1", {generator: row.generator}));
assert.equal(buildProfile(rows, descriptions).series.a.length, 3);
assert.throws(() => buildProfile(rows, []), /Missing benchmark description/);
});
// Execute the actual weighting cell so the original plot's math stays covered.
const page = readFileSync(new URL("../docs/index.md", import.meta.url), "utf8");
const cell = [...page.matchAll(/```js\n([\s\S]*?)\n```/g)].map((match) => match[1]).find((code) => code.includes("const ok ="));
const curvesFor = new Function("profile", "keep", "drop", "countEl", `${cell}\nreturn {curves, total};`);
test("the page awaits both CSVs and the run metadata before building the profile", async () => {
const loadCell = [...page.matchAll(/```js\n([\s\S]*?)\n```/g)][0][1].replace(/^import .*;\n/m, "");
const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;
const load = new AsyncFunction("FileAttachment", "buildProfile", `${loadCell}\nreturn profile;`);
const files = {
"./data/results.csv": [result("one", "a", "1")],
"./data/benchmarks.csv": [description("one")],
"./data/run.json": {frameworks: ["a", "failed"]}
};
const profile = await load((path) => ({csv: async () => files[path], json: async () => files[path]}), buildProfile);
assert.deepEqual(profile.series, {a: [[0, 1]], failed: []});
});
test("the plot weights benchmarks equally and recomputes weights after tag filtering", () => {
const profile = {xMax: 2, problems: [
{benchmark: "A", tags: ["dense"]}, {benchmark: "A", tags: ["sparse"]},
{benchmark: "B", tags: ["dense"]}
], series: {a: [[0, 1], [2, 2]], failed: []}};
const countEl = {};
assert.equal(curvesFor(profile, [], [], countEl).curves.filter((point) => point.framework === "a").at(-1).pct, 75);
assert.equal(curvesFor(profile, ["dense"], [], countEl).curves.filter((point) => point.framework === "a").at(-1).pct, 100);
assert.deepEqual(curvesFor(profile, ["dense"], ["dense"], countEl), {curves: [], total: 0});
assert.deepEqual(curvesFor(profile, [], [], countEl).curves.filter((point) => point.framework === "failed").map((point) => point.pct), [0, 0]);
});