Skip to content

Commit e1acad0

Browse files
authored
Simplify updateUIAfterRun (#99)
- Rewrite score getter to use dubScore values directly - Add allScores() helper that also returns the Score value - Rewrite scoreIdentifiers to use allScores() - Implement single updateUIAfterRun() and use allScores()
1 parent d9ee876 commit e1acad0

File tree

2 files changed

+83
-127
lines changed

2 files changed

+83
-127
lines changed

JetStreamDriver.js

Lines changed: 56 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -126,21 +126,6 @@ function assert(b, m = "") {
126126
throw new Error(`Bad assertion: ${m}`);
127127
}
128128

129-
function firstID(benchmark) {
130-
return `results-cell-${benchmark.name}-first`;
131-
}
132-
133-
function worst4ID(benchmark) {
134-
return `results-cell-${benchmark.name}-worst4`;
135-
}
136-
137-
function avgID(benchmark) {
138-
return `results-cell-${benchmark.name}-avg`;
139-
}
140-
141-
function scoreID(benchmark) {
142-
return `results-cell-${benchmark.name}-score`;
143-
}
144129

145130
function mean(values) {
146131
assert(values instanceof Array);
@@ -679,9 +664,20 @@ class Benchmark {
679664
}
680665

681666
get score() {
667+
const subScores = Object.values(this.subScores());
668+
return geomean(subScores);
669+
}
670+
671+
subScores() {
682672
throw new Error("Subclasses need to implement this");
683673
}
684674

675+
allScores() {
676+
const allScores = this.subScores();
677+
allScores["Score"] = this.score;
678+
return allScores;
679+
}
680+
685681
get prerunCode() { return null; }
686682

687683
get preIterationCode() {
@@ -993,15 +989,23 @@ class Benchmark {
993989
this.preloads = Object.entries(this.plan.preload ?? {});
994990
}
995991

996-
scoreIdentifiers() { throw new Error("Must be implemented by subclasses"); }
992+
scoreIdentifiers() {
993+
const ids = Object.keys(this.allScores()).map(name => this.scoreIdentifier(name));
994+
return ids;
995+
}
996+
997+
scoreIdentifier(scoreName) {
998+
return `results-cell-${this.name}-${scoreName}`;
999+
}
9971000

9981001
updateUIBeforeRun() {
999-
if (!isInBrowser) {
1000-
if (!dumpJSONResults)
1001-
console.log(`Running ${this.name}:`);
1002-
return;
1003-
}
1002+
if (!dumpJSONResults)
1003+
console.log(`Running ${this.name}:`);
1004+
if (isInBrowser)
1005+
this.updateUIBeforeRunInBrowser();
1006+
}
10041007

1008+
updateUIBeforeRunInBrowser() {
10051009
const containerUI = document.getElementById("results");
10061010
const resultsBenchmarkUI = document.getElementById(`benchmark-${this.name}`);
10071011
containerUI.insertBefore(resultsBenchmarkUI, containerUI.firstChild);
@@ -1012,13 +1016,43 @@ class Benchmark {
10121016
}
10131017

10141018
updateUIAfterRun() {
1015-
if (!isInBrowser)
1019+
const scoreEntries = Object.entries(this.allScores());
1020+
if (isInBrowser)
1021+
this.updateUIAfterRunInBrowser(scoreEntries);
1022+
if (dumpJSONResults)
10161023
return;
1024+
this.updateConsoleAfterRun(scoreEntries);
1025+
}
10171026

1027+
updateUIAfterRunInBrowser(scoreEntries) {
10181028
const benchmarkResultsUI = document.getElementById(`benchmark-${this.name}`);
10191029
benchmarkResultsUI.classList.remove("benchmark-running");
10201030
benchmarkResultsUI.classList.add("benchmark-done");
10211031

1032+
for (const [name, value] of scoreEntries)
1033+
document.getElementById(this.scoreIdentifier(name)).innerHTML = uiFriendlyScore(value);
1034+
}
1035+
1036+
updateConsoleAfterRun(scoreEntries) {
1037+
// FIXME: consider removing this mapping.
1038+
// Rename for backwards compatibility.
1039+
const legacyScoreNameMap = {
1040+
__proto__: null,
1041+
"First": "Startup",
1042+
"Worst": "Worst Case",
1043+
"MainRun": "Tests",
1044+
"Runtime": "Run time",
1045+
};
1046+
for (let [name, value] of scoreEntries) {
1047+
if (name in legacyScoreNameMap)
1048+
name = legacyScoreNameMap[name];
1049+
console.log(` ${name}:`, uiFriendlyScore(value));
1050+
}
1051+
if (RAMification) {
1052+
console.log(" Current Footprint:", uiFriendlyNumber(this.currentFootprint));
1053+
console.log(" Peak Footprint:", uiFriendlyNumber(this.peakFootprint));
1054+
}
1055+
console.log(" Wall time:", uiFriendlyDuration(this.endTime - this.startTime));
10221056
}
10231057
};
10241058

@@ -1063,46 +1097,13 @@ class DefaultBenchmark extends Benchmark {
10631097
this.averageScore = toScore(this.averageTime);
10641098
}
10651099

1066-
get score() {
1067-
return geomean([this.firstIterationScore, this.worst4Score, this.averageScore]);
1068-
}
1069-
10701100
subScores() {
10711101
return {
10721102
"First": this.firstIterationScore,
10731103
"Worst": this.worst4Score,
10741104
"Average": this.averageScore,
10751105
};
10761106
}
1077-
1078-
scoreIdentifiers() {
1079-
return [firstID(this), worst4ID(this), avgID(this), scoreID(this)];
1080-
}
1081-
1082-
updateUIAfterRun() {
1083-
super.updateUIAfterRun();
1084-
1085-
if (isInBrowser) {
1086-
document.getElementById(firstID(this)).innerHTML = uiFriendlyScore(this.firstIterationScore);
1087-
document.getElementById(worst4ID(this)).innerHTML = uiFriendlyScore(this.worst4Score);
1088-
document.getElementById(avgID(this)).innerHTML = uiFriendlyScore(this.averageScore);
1089-
document.getElementById(scoreID(this)).innerHTML = uiFriendlyScore(this.score);
1090-
return;
1091-
}
1092-
1093-
if (dumpJSONResults)
1094-
return;
1095-
1096-
console.log(" Startup:", uiFriendlyScore(this.firstIterationScore));
1097-
console.log(" Worst Case:", uiFriendlyScore(this.worst4Score));
1098-
console.log(" Average:", uiFriendlyScore(this.averageScore));
1099-
console.log(" Score:", uiFriendlyScore(this.score));
1100-
if (RAMification) {
1101-
console.log(" Current Footprint:", uiFriendlyNumber(this.currentFootprint));
1102-
console.log(" Peak Footprint:", uiFriendlyNumber(this.peakFootprint));
1103-
}
1104-
console.log(" Wall time:", uiFriendlyDuration(this.endTime - this.startTime));
1105-
}
11061107
}
11071108

11081109
class AsyncBenchmark extends DefaultBenchmark {
@@ -1250,10 +1251,6 @@ class WSLBenchmark extends Benchmark {
12501251
this.mainRunScore = toScore(results[1]);
12511252
}
12521253

1253-
get score() {
1254-
return geomean([this.stdlibScore, this.mainRunScore]);
1255-
}
1256-
12571254
get runnerCode() {
12581255
return `
12591256
let benchmark = new Benchmark();
@@ -1292,33 +1289,6 @@ class WSLBenchmark extends Benchmark {
12921289
"MainRun": this.mainRunScore,
12931290
};
12941291
}
1295-
1296-
scoreIdentifiers() {
1297-
return ["wsl-stdlib-score", "wsl-tests-score", "wsl-score-score"];
1298-
}
1299-
1300-
updateUIAfterRun() {
1301-
super.updateUIAfterRun();
1302-
1303-
if (isInBrowser) {
1304-
document.getElementById("wsl-stdlib-score").innerHTML = uiFriendlyScore(this.stdlibScore);
1305-
document.getElementById("wsl-tests-score").innerHTML = uiFriendlyScore(this.mainRunScore);
1306-
document.getElementById("wsl-score-score").innerHTML = uiFriendlyScore(this.score);
1307-
return;
1308-
}
1309-
1310-
if (dumpJSONResults)
1311-
return;
1312-
1313-
console.log(" Stdlib:", uiFriendlyScore(this.stdlibScore));
1314-
console.log(" Tests:", uiFriendlyScore(this.mainRunScore));
1315-
console.log(" Score:", uiFriendlyScore(this.score));
1316-
if (RAMification) {
1317-
console.log(" Current Footprint:", uiFriendlyNumber(this.currentFootprint));
1318-
console.log(" Peak Footprint:", uiFriendlyNumber(this.peakFootprint));
1319-
}
1320-
console.log(" Wall time:", uiFriendlyDuration(this.endTime - this.startTime));
1321-
}
13221292
};
13231293

13241294
class WasmLegacyBenchmark extends Benchmark {
@@ -1338,10 +1308,6 @@ class WasmLegacyBenchmark extends Benchmark {
13381308
this.runScore = toScore(results[1]);
13391309
}
13401310

1341-
get score() {
1342-
return geomean([this.startupScore, this.runScore]);
1343-
}
1344-
13451311
get prerunCode() {
13461312
const str = `
13471313
let verbose = false;
@@ -1464,43 +1430,6 @@ class WasmLegacyBenchmark extends Benchmark {
14641430
"Runtime": this.runScore,
14651431
};
14661432
}
1467-
1468-
get startupID() {
1469-
return `wasm-startup-id${this.name}`;
1470-
}
1471-
get runID() {
1472-
return `wasm-run-id${this.name}`;
1473-
}
1474-
get scoreID() {
1475-
return `wasm-score-id${this.name}`;
1476-
}
1477-
1478-
scoreIdentifiers() {
1479-
return [this.startupID, this.runID, this.scoreID];
1480-
}
1481-
1482-
updateUIAfterRun() {
1483-
super.updateUIAfterRun();
1484-
1485-
if (isInBrowser) {
1486-
document.getElementById(this.startupID).innerHTML = uiFriendlyScore(this.startupScore);
1487-
document.getElementById(this.runID).innerHTML = uiFriendlyScore(this.runScore);
1488-
document.getElementById(this.scoreID).innerHTML = uiFriendlyScore(this.score);
1489-
return;
1490-
}
1491-
1492-
if (dumpJSONResults)
1493-
return;
1494-
1495-
console.log(" Startup:", uiFriendlyScore(this.startupScore));
1496-
console.log(" Run time:", uiFriendlyScore(this.runScore));
1497-
console.log(" Score:", uiFriendlyScore(this.score));
1498-
if (RAMification) {
1499-
console.log(" Current Footprint:", uiFriendlyNumber(this.currentFootprint));
1500-
console.log(" Peak Footprint:", uiFriendlyNumber(this.peakFootprint));
1501-
}
1502-
console.log(" Wall time:", uiFriendlyDuration(this.endTime - this.startTime));
1503-
}
15041433
};
15051434

15061435
function dotnetPreloads(type)

tests/unit-tests.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,30 @@ function assertEquals(actual, expected, message) {
6464
assertTrue(enabledBenchmarkNames.has(benchmark.name));
6565
}
6666
})();
67+
68+
69+
(function testBenchmarkSubScores() {
70+
for (const benchmark of BENCHMARKS) {
71+
const subScores = benchmark.subScores();
72+
assertTrue(subScores instanceof Object);
73+
assertTrue(Object.keys(subScores).length > 0);
74+
for (const [name, value] of Object.entries(subScores)) {
75+
assertTrue(typeof(name) == "string");
76+
// "Score" can only be part of allScores().
77+
assertFalse(name == "Score");
78+
// Without running all values should be null.
79+
assertEquals(value, null);
80+
}
81+
}
82+
})();
83+
84+
(function testBenchmarkAllScores() {
85+
for (const benchmark of BENCHMARKS) {
86+
const subScores = benchmark.subScores();
87+
const allScores = benchmark.allScores();
88+
assertTrue("Score" in allScores);
89+
// All subScore items are part of allScores.
90+
for (const name of Object.keys(subScores))
91+
assertTrue(name in allScores);
92+
}
93+
})();

0 commit comments

Comments
 (0)