Skip to content

Commit d6fb3ce

Browse files
authored
Merge branch 'WebKit:main' into add-nutrient-benchmark
2 parents eed424f + c1851d9 commit d6fb3ce

File tree

6 files changed

+96
-92
lines changed

6 files changed

+96
-92
lines changed

JetStream.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ a.button {
224224
color: transparent;
225225
background-image: linear-gradient(132deg, #96E5FF 0%, #96E5FF 2%, #86D9FF 42%, #8BDAFF 84%, #96E5FF 98%, #96E5FF 100%);
226226
-webkit-background-clip: text;
227-
background-size: 1200px 100%;
228227
background-repeat: no-repeat;
229228
-webkit-touch-callout: none;
230229
-webkit-user-select: none;

JetStreamDriver.js

Lines changed: 20 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ if (isInBrowser) {
115115

116116
function assert(b, m = "") {
117117
if (!b)
118-
throw new Error("Bad assertion: " + m);
118+
throw new Error(`Bad assertion: ${m}`);
119119
}
120120

121121
function firstID(benchmark) {
@@ -177,17 +177,8 @@ function uiFriendlyScore(num) {
177177
return uiFriendlyNumber(num);
178178
}
179179

180-
function uiFriendlyDuration(time)
181-
{
182-
const minutes = time.getMinutes();
183-
const seconds = time.getSeconds();
184-
const milliSeconds = time.getMilliseconds();
185-
let result = "" + minutes + ":";
186-
187-
result = result + (seconds < 10 ? "0" : "") + seconds + ".";
188-
result = result + (milliSeconds < 10 ? "00" : (milliSeconds < 100 ? "0" : "")) + milliSeconds;
189-
190-
return result;
180+
function uiFriendlyDuration(time) {
181+
return `${time.toFixed(3)} ms`;
191182
}
192183

193184
const fileLoader = (function() {
@@ -321,7 +312,7 @@ class Driver {
321312

322313
if (isInBrowser) {
323314
summaryElement.classList.add('done');
324-
summaryElement.innerHTML = "<div class=\"score\">" + uiFriendlyScore(geomean(allScores)) + "</div><label>Score</label>";
315+
summaryElement.innerHTML = `<div class="score">${uiFriendlyScore(geomean(allScores))}</div><label>Score</label>`;
325316
summaryElement.onclick = displayCategoryScores;
326317
if (showScoreDetails)
327318
displayCategoryScores();
@@ -391,7 +382,7 @@ class Driver {
391382

392383
const magicFrame = magic.contentDocument.getElementById("magicframe");
393384
magicFrame.contentDocument.open();
394-
magicFrame.contentDocument.write("<!DOCTYPE html><head><title>benchmark payload</title></head><body>\n" + string + "</body></html>");
385+
magicFrame.contentDocument.write(`<!DOCTYPE html><head><title>benchmark payload</title></head><body>\n${string}</body></html>`);
395386

396387
return magicFrame;
397388
}
@@ -403,11 +394,11 @@ class Driver {
403394
let text = "";
404395
let newBenchmarks = [];
405396
for (const benchmark of this.benchmarks) {
406-
const id = JSON.stringify(benchmark.constructor.scoreDescription());
407-
const description = JSON.parse(id);
397+
const description = Object.keys(benchmark.subScores());
398+
description.push("Score");
408399

409400
newBenchmarks.push(benchmark);
410-
const scoreIds = benchmark.scoreIdentifiers()
401+
const scoreIds = benchmark.scoreIdentifiers();
411402
const overallScoreId = scoreIds.pop();
412403

413404
if (isInBrowser) {
@@ -650,9 +641,6 @@ class Benchmark {
650641
let benchmarkName = "${this.name}";
651642
652643
for (let i = 0; i < ${this.iterations}; i++) {
653-
if (__benchmark.prepareForNextIteration)
654-
__benchmark.prepareForNextIteration();
655-
656644
${this.preIterationCode}
657645
658646
const iterationMarkLabel = benchmarkName + "-iteration-" + i;
@@ -662,14 +650,13 @@ class Benchmark {
662650
__benchmark.runIteration();
663651
let end = performance.now();
664652
665-
performanceMeasure(iterationMarkLabel, iterationStartMark);
653+
performance.measure(iterationMarkLabel, iterationMarkLabel);
666654
667655
${this.postIterationCode}
668656
669657
results.push(Math.max(1, end - start));
670658
}
671-
if (__benchmark.validate)
672-
__benchmark.validate(${this.iterations});
659+
__benchmark.validate?.(${this.iterations});
673660
top.currentResolve(results);`;
674661
}
675662

@@ -684,7 +671,7 @@ class Benchmark {
684671
get prerunCode() { return null; }
685672

686673
get preIterationCode() {
687-
let code = "";
674+
let code = `__benchmark.prepareForNextIteration?.();`;
688675
if (this.plan.deterministicRandom)
689676
code += `Math.random.__resetSeed();`;
690677

@@ -731,19 +718,11 @@ class Benchmark {
731718
const isInBrowser = ${isInBrowser};
732719
const isD8 = ${isD8};
733720
if (typeof performance.mark === 'undefined') {
734-
performance.mark = function() {};
721+
performance.mark = function(name) { return { name }};
735722
}
736723
if (typeof performance.measure === 'undefined') {
737724
performance.measure = function() {};
738725
}
739-
function performanceMeasure(name, mark) {
740-
// D8 does not implement the official web API.
741-
// Also the performance.mark polyfill returns an undefined mark.
742-
if (isD8 || typeof mark === "undefined")
743-
performance.measure(name, mark);
744-
else
745-
performance.measure(name, mark.name);
746-
}
747726
`);
748727

749728
if (!!this.plan.deterministicRandom) {
@@ -1018,7 +997,6 @@ class Benchmark {
1018997
return this._resourcesPromise;
1019998
}
1020999

1021-
static scoreDescription() { throw new Error("Must be implemented by subclasses."); }
10221000
scoreIdentifiers() { throw new Error("Must be implemented by subclasses"); }
10231001

10241002
updateUIBeforeRun() {
@@ -1101,10 +1079,6 @@ class DefaultBenchmark extends Benchmark {
11011079
};
11021080
}
11031081

1104-
static scoreDescription() {
1105-
return ["First", "Worst", "Average", "Score"];
1106-
}
1107-
11081082
scoreIdentifiers() {
11091083
return [firstID(this), worst4ID(this), avgID(this), scoreID(this)];
11101084
}
@@ -1131,7 +1105,7 @@ class DefaultBenchmark extends Benchmark {
11311105
console.log(" Current Footprint:", uiFriendlyNumber(this.currentFootprint));
11321106
console.log(" Peak Footprint:", uiFriendlyNumber(this.peakFootprint));
11331107
}
1134-
console.log(" Wall time:", uiFriendlyDuration(new Date(this.endTime - this.startTime)));
1108+
console.log(" Wall time:", uiFriendlyDuration(this.endTime - this.startTime));
11351109
}
11361110
}
11371111

@@ -1185,8 +1159,7 @@ class AsyncBenchmark extends DefaultBenchmark {
11851159
return `
11861160
async function doRun() {
11871161
let __benchmark = new Benchmark();
1188-
if (__benchmark.init)
1189-
await __benchmark.init();
1162+
await __benchmark.init?.();
11901163
let results = [];
11911164
let benchmarkName = "${this.name}";
11921165
@@ -1200,14 +1173,13 @@ class AsyncBenchmark extends DefaultBenchmark {
12001173
await __benchmark.runIteration();
12011174
let end = performance.now();
12021175
1203-
performanceMeasure(iterationMarkLabel, iterationStartMark);
1176+
performance.measure(iterationMarkLabel, iterationMarkLabel);
12041177
12051178
${this.postIterationCode}
12061179
12071180
results.push(Math.max(1, end - start));
12081181
}
1209-
if (__benchmark.validate)
1210-
__benchmark.validate(${this.iterations});
1182+
__benchmark.validate?.(${this.iterations});
12111183
top.currentResolve(results);
12121184
}
12131185
doRun().catch((error) => { top.currentReject(error); });`
@@ -1300,7 +1272,7 @@ class WSLBenchmark extends Benchmark {
13001272
benchmark.buildStdlib();
13011273
results.push(performance.now() - start);
13021274
1303-
performanceMeasure(markLabel, startMark);
1275+
performance.measure(markLabel, markLabel);
13041276
}
13051277
13061278
{
@@ -1311,7 +1283,7 @@ class WSLBenchmark extends Benchmark {
13111283
benchmark.run();
13121284
results.push(performance.now() - start);
13131285
1314-
performanceMeasure(markLabel, startMark);
1286+
performance.measure(markLabel, markLabel);
13151287
}
13161288
13171289
top.currentResolve(results);
@@ -1325,10 +1297,6 @@ class WSLBenchmark extends Benchmark {
13251297
};
13261298
}
13271299

1328-
static scoreDescription() {
1329-
return ["Stdlib", "MainRun", "Score"];
1330-
}
1331-
13321300
scoreIdentifiers() {
13331301
return ["wsl-stdlib-score", "wsl-tests-score", "wsl-score-score"];
13341302
}
@@ -1353,7 +1321,7 @@ class WSLBenchmark extends Benchmark {
13531321
console.log(" Current Footprint:", uiFriendlyNumber(this.currentFootprint));
13541322
console.log(" Peak Footprint:", uiFriendlyNumber(this.peakFootprint));
13551323
}
1356-
console.log(" Wall time:", uiFriendlyDuration(new Date(this.endTime - this.startTime)));
1324+
console.log(" Wall time:", uiFriendlyDuration(this.endTime - this.startTime));
13571325
}
13581326
};
13591327

@@ -1501,10 +1469,6 @@ class WasmLegacyBenchmark extends Benchmark {
15011469
};
15021470
}
15031471

1504-
static scoreDescription() {
1505-
return ["Startup", "Runtime", "Score"];
1506-
}
1507-
15081472
get startupID() {
15091473
return `wasm-startup-id${this.name}`;
15101474
}
@@ -1539,7 +1503,7 @@ class WasmLegacyBenchmark extends Benchmark {
15391503
console.log(" Current Footprint:", uiFriendlyNumber(this.currentFootprint));
15401504
console.log(" Peak Footprint:", uiFriendlyNumber(this.peakFootprint));
15411505
}
1542-
console.log(" Wall time:", uiFriendlyDuration(new Date(this.endTime - this.startTime)));
1506+
console.log(" Wall time:", uiFriendlyDuration(this.endTime - this.startTime));
15431507
}
15441508
};
15451509

cli.js

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,7 @@
2323
* THE POSSIBILITY OF SUCH DAMAGE.
2424
*/
2525

26-
const isInBrowser = false;
27-
console = {
28-
log: globalThis?.console?.log ?? print,
29-
error: globalThis?.console?.error ?? print,
30-
}
31-
32-
const isD8 = typeof Realm !== "undefined";
33-
if (isD8)
34-
globalThis.readFile = read;
35-
const isSpiderMonkey = typeof newGlobal !== "undefined";
36-
if (isSpiderMonkey) {
37-
globalThis.readFile = readRelativeToScript;
38-
globalThis.arguments = scriptArgs;
39-
}
40-
41-
if (typeof arguments !== "undefined" && arguments.length > 0)
42-
testList = arguments.slice();
43-
if (typeof testList === "undefined")
44-
testList = undefined;
45-
46-
if (typeof testIterationCount === "undefined")
47-
testIterationCount = undefined;
48-
49-
if (typeof runMode !== "undefined" && runMode == "RAMification")
50-
RAMification = true;
51-
else
52-
RAMification = false;
53-
26+
load("./shell-config.js")
5427
load("./JetStreamDriver.js");
5528

5629
async function runJetStream() {

shell-config.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (C) 2018 Apple Inc. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
*
13+
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17+
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23+
* THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
const isInBrowser = false;
27+
console = {
28+
log: globalThis?.console?.log ?? print,
29+
error: globalThis?.console?.error ?? print,
30+
}
31+
32+
const isD8 = typeof Realm !== "undefined";
33+
if (isD8)
34+
globalThis.readFile = read;
35+
const isSpiderMonkey = typeof newGlobal !== "undefined";
36+
if (isSpiderMonkey) {
37+
globalThis.readFile = readRelativeToScript;
38+
globalThis.arguments = scriptArgs;
39+
}
40+
41+
if (typeof arguments !== "undefined" && arguments.length > 0)
42+
testList = arguments.slice();
43+
if (typeof testList === "undefined")
44+
testList = undefined;
45+
46+
if (typeof testIterationCount === "undefined")
47+
testIterationCount = undefined;
48+
49+
if (typeof runMode !== "undefined" && runMode == "RAMification")
50+
RAMification = true;
51+
else
52+
RAMification = false;

tests/run-shell.mjs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ const SHELL_NAME = (function() {
6666
const FILE_PATH = fileURLToPath(import.meta.url);
6767
const SRC_DIR = path.dirname(path.dirname(FILE_PATH));
6868
const CLI_PATH = path.join(SRC_DIR, "cli.js");
69+
const UNIT_TEST_PATH = path.join(SRC_DIR, "tests", "unit-tests.js");
6970

70-
const BASE_CLI_ARGS_WITH_OPTIONS = [CLI_PATH];
71-
if (SHELL_NAME != "spidermonkey")
72-
BASE_CLI_ARGS_WITH_OPTIONS.push("--");
73-
Object.freeze(BASE_CLI_ARGS_WITH_OPTIONS);
71+
function convertCliArgs(cli, ...cliArgs) {
72+
if (SHELL_NAME == "spidermonkey")
73+
return [cli, ...cliArgs]
74+
return [cli, "--", ...cliArgs];
75+
}
7476

7577
const GITHUB_ACTIONS_OUTPUT = "GITHUB_ACTIONS_OUTPUT" in process.env;
7678

@@ -133,10 +135,10 @@ function sh(binary, args) {
133135
async function runTests() {
134136
const shellBinary = logGroup(`Installing JavaScript Shell: ${SHELL_NAME}`, testSetup);
135137
let success = true;
136-
success &&= runTest("Run Complete Suite", () => sh(shellBinary, [CLI_PATH]));
138+
success &&= runTest("Run UnitTests", () => sh(shellBinary, [UNIT_TEST_PATH]));
139+
success &&= runTest("Run Complete Suite", () => sh(shellBinary, convertCliArgs(CLI_PATH)));
137140
success &&= runTest("Run Single Suite", () => {
138-
const singleTestArgs = [...BASE_CLI_ARGS_WITH_OPTIONS, "proxy-mobx"];
139-
sh(shellBinary, singleTestArgs);
141+
sh(shellBinary, convertCliArgs(CLI_PATH, "proxy-mobx"));
140142
});
141143
if (!success) {
142144
process.exit(1)

tests/unit-tests.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
load("shell-config.js")
2+
load("JetStreamDriver.js");
3+
4+
function assertTrue(condition, message) {
5+
if (!condition) {
6+
throw new Error(message || "Assertion failed");
7+
}
8+
}
9+
10+
(function testTagsAreStrings() {
11+
for (const benchmark of BENCHMARKS) {
12+
benchmark.tags.forEach(tag => assertTrue(typeof(tag) == "string"))
13+
}
14+
})();

0 commit comments

Comments
 (0)