Skip to content

Commit bcfc372

Browse files
authored
Merge pull request #133 from kmiller68/add-grouped-benchmark-for-sunspider
Add a new GroupedBenchmark that runs a series of benchmarks.
2 parents 6561562 + dbbea1a commit bcfc372

File tree

2 files changed

+94
-5
lines changed

2 files changed

+94
-5
lines changed

JetStreamDriver.js

Lines changed: 92 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ class Driver {
262262

263263
if (isInBrowser && globalThis.prefetchResources) {
264264
const cache = JetStream.blobDataCache;
265-
for (const file of benchmark.plan.files) {
265+
for (const file of benchmark.files) {
266266
const blobData = cache[file];
267267
blobData.refCount--;
268268
if (!blobData.refCount)
@@ -709,6 +709,7 @@ class Benchmark {
709709
}
710710

711711
get name() { return this.plan.name; }
712+
get files() { return this.plan.files; }
712713

713714
get isDone() {
714715
return this._state == BenchmarkState.DONE || this._state == BenchmarkState.ERROR;
@@ -1121,6 +1122,89 @@ class Benchmark {
11211122
}
11221123
};
11231124

1125+
class GroupedBenchmark extends Benchmark {
1126+
constructor(plan, benchmarks) {
1127+
super(plan);
1128+
console.assert(benchmarks.length);
1129+
for (const benchmark of benchmarks) {
1130+
// FIXME: Tags don't work for grouped tests anyway but if they did then this would be weird and probably wrong.
1131+
console.assert(!benchmark.hasAnyTag("Default"), `Grouped benchmark sub-benchmarks shouldn't have the "Default" tag`, benchmark.tags);
1132+
}
1133+
benchmarks.sort((a, b) => a.name.toLowerCase() < b.name.toLowerCase() ? 1 : -1);
1134+
this.benchmarks = benchmarks;
1135+
}
1136+
1137+
async prefetchResourcesForBrowser() {
1138+
for (const benchmark of this.benchmarks)
1139+
await benchmark.prefetchResourcesForBrowser();
1140+
}
1141+
1142+
async retryPrefetchResourcesForBrowser() {
1143+
for (const benchmark of this.benchmarks)
1144+
await benchmark.retryPrefetchResourcesForBrowser();
1145+
}
1146+
1147+
prefetchResourcesForShell() {
1148+
for (const benchmark of this.benchmarks)
1149+
benchmark.prefetchResourcesForShell();
1150+
}
1151+
1152+
get files() {
1153+
let files = [];
1154+
for (const benchmark of this.benchmarks)
1155+
files = files.concat(benchmark.files);
1156+
return files;
1157+
}
1158+
1159+
async run() {
1160+
this._state = BenchmarkState.PREPARE;
1161+
performance.mark(this.name);
1162+
this.startTime = performance.now();
1163+
1164+
let benchmark;
1165+
try {
1166+
this._state = BenchmarkState.RUNNING;
1167+
for (benchmark of this.benchmarks)
1168+
await benchmark.run();
1169+
} catch (e) {
1170+
this._state = BenchmarkState.ERROR;
1171+
console.log(`Error in runCode of grouped benchmark ${benchmark.name}: `, e);
1172+
console.log(e.stack);
1173+
throw e;
1174+
} finally {
1175+
this._state = BenchmarkState.FINALIZE;
1176+
}
1177+
1178+
this.endTime = performance.now();
1179+
performance.measure(this.name, this.name);
1180+
1181+
this.processResults();
1182+
this._state = BenchmarkState.DONE;
1183+
}
1184+
1185+
processResults() {
1186+
this.results = [];
1187+
for (const benchmark of this.benchmarks)
1188+
this.results = this.results.concat(benchmark.results);
1189+
}
1190+
1191+
subScores() {
1192+
const results = {};
1193+
1194+
for (const benchmark of this.benchmarks) {
1195+
let scores = benchmark.subScores();
1196+
for (let subScore in scores) {
1197+
results[subScore] ??= [];
1198+
results[subScore].push(scores[subScore]);
1199+
}
1200+
}
1201+
1202+
for (let subScore in results)
1203+
results[subScore] = geomeanScore(results[subScore]);
1204+
return results;
1205+
}
1206+
};
1207+
11241208
class DefaultBenchmark extends Benchmark {
11251209
constructor(...args) {
11261210
super(...args);
@@ -2433,15 +2517,20 @@ const SUNSPIDER_TESTS = [
24332517
"string-unpack-code",
24342518
"tagcloud",
24352519
];
2520+
let SUNSPIDER_BENCHMARKS = [];
24362521
for (const test of SUNSPIDER_TESTS) {
2437-
BENCHMARKS.push(new DefaultBenchmark({
2522+
SUNSPIDER_BENCHMARKS.push(new DefaultBenchmark({
24382523
name: `${test}-SP`,
24392524
files: [
24402525
`./SunSpider/${test}.js`
24412526
],
2442-
tags: ["Default", "SunSpider"],
2527+
tags: [],
24432528
}));
24442529
}
2530+
BENCHMARKS.push(new GroupedBenchmark({
2531+
name: "Sunspider",
2532+
tags: ["Default", "SunSpider"],
2533+
}, SUNSPIDER_BENCHMARKS))
24452534

24462535
// WTB (Web Tooling Benchmark) tests
24472536
const WTB_TESTS = [

tests/unit-tests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ function assertEquals(actual, expected, message) {
8686
assertTrue(typeof(name) == "string");
8787
// "Score" can only be part of allScores().
8888
assertFalse(name == "Score");
89-
// Without running all values should be null.
90-
assertEquals(value, null);
89+
// Without running values should be either null (or 0 for GroupedBenchmark)
90+
assertFalse(value)
9191
}
9292
}
9393
})();

0 commit comments

Comments
 (0)