Skip to content

Commit a55964e

Browse files
committed
more
1 parent 36c7b48 commit a55964e

File tree

7 files changed

+2859
-57
lines changed

7 files changed

+2859
-57
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,6 @@ on:
1010
workflow_dispatch:
1111

1212
jobs:
13-
linters:
14-
name: Linters
15-
runs-on: macos-latest
16-
steps:
17-
- name: Checkout Branch
18-
uses: actions/checkout@v3
19-
- name: Setup Node
20-
uses: actions/setup-node@v3
21-
with:
22-
node-version: 18.13.0
23-
- name: Install
24-
run: npm install
25-
- name: Run linters
26-
run: npm run format
27-
- name: Check if anything changed
28-
run: |
29-
git_status="`LC_ALL=C git status --porcelain --ignore-submodules -unormal 2>&1`"
30-
if [ -n "$git_status" ]; then
31-
printf "Some file(s) changed as the result of formatting, this means that you need to run the formatter on your patch.\n"
32-
printf "Here is what changed:\n"
33-
printf -- "$git_status\n\n"
34-
printf "And here is the diff:\n"
35-
git diff -U8
36-
exit 1
37-
fi
3813
build:
3914
name: Build
4015
runs-on: macos-latest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_Store
22
.directory
3+
/node_modules
34

45
# Ignore auto-generated files by VS & VSCode.
56
/.vs/

JetStreamDriver.js

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,44 @@
2727

2828
const measureTotalTimeAsSubtest = false; // Once we move to preloading all resources, it would be good to turn this on.
2929

30+
const defaultIterationCount = 120;
31+
const defaultWorstCaseCount = 4;
32+
3033
globalThis.performance ??= Date;
3134
globalThis.RAMification ??= false;
3235
globalThis.testIterationCount ??= undefined;
3336
globalThis.testIterationCountMap ??= new Map();
37+
globalThis.testWorstCaseCount ??= undefined;
3438
globalThis.testWorstCaseCountMap ??= new Map();
3539
globalThis.dumpJSONResults ??= false;
3640
globalThis.customTestList ??= [];
37-
3841
let shouldReport = false;
42+
43+
function getIntParam(urlParams, key) {
44+
if (!urlParams.has(key))
45+
return undefined
46+
const rawValue = urlParams.get(key);
47+
const value = parseInt(rawValue);
48+
if (value <= 0)
49+
throw new Error(`Expected positive value for ${key}, but got ${rawValue}`)
50+
return value
51+
}
52+
3953
if (typeof(URLSearchParams) !== "undefined") {
4054
const urlParameters = new URLSearchParams(window.location.search);
4155
shouldReport = urlParameters.has('report') && urlParameters.get('report').toLowerCase() == 'true';
4256
if (urlParameters.has('test'))
4357
customTestList = urlParameters.getAll("test");
58+
globalThis.testIterationCount = getIntParam(urlParameters, "iterationCount");
59+
globalThis.testWorstCaseCount = getIntParam(urlParameters, "worstCaseCount");
4460
}
4561

62+
63+
4664
// Used for the promise representing the current benchmark run.
4765
this.currentResolve = null;
4866
this.currentReject = null;
4967

50-
const defaultIterationCount = 120;
51-
const defaultWorstCaseCount = 4;
52-
5368
let showScoreDetails = false;
5469
let categoryScores = null;
5570

@@ -77,6 +92,8 @@ function getIterationCount(plan) {
7792
function getWorstCaseCount(plan) {
7893
if (testWorstCaseCountMap.has(plan.name))
7994
return testWorstCaseCountMap.get(plan.name);
95+
if (testWorstCaseCount)
96+
return testWorstCaseCount;
8097
if (plan.worstCaseCount)
8198
return plan.worstCaseCount;
8299
return defaultWorstCaseCount;
@@ -214,6 +231,7 @@ const fileLoader = (function() {
214231

215232
class Driver {
216233
constructor() {
234+
this.isReady = false;
217235
this.benchmarks = [];
218236
this.blobDataCache = { };
219237
this.loadCache = { };
@@ -308,6 +326,11 @@ class Driver {
308326

309327
this.reportScoreToRunBenchmarkRunner();
310328
this.dumpJSONResultsIfNeeded();
329+
if (isInBrowser) {
330+
globalThis.dispatchEvent(new CustomEvent("JetStreamDone", {
331+
detail: this.resultsObject()
332+
}));
333+
}
311334
}
312335

313336
runCode(string)
@@ -351,7 +374,6 @@ class Driver {
351374
var magicFrame = magic.contentDocument.getElementById("magicframe");
352375
magicFrame.contentDocument.open();
353376
magicFrame.contentDocument.write("<!DOCTYPE html><head><title>benchmark payload</title></head><body>\n" + string + "</body></html>");
354-
355377
return magicFrame;
356378
}
357379

@@ -414,8 +436,12 @@ class Driver {
414436
await this.prefetchResourcesForBrowser();
415437
await this.fetchResources();
416438
this.prepareToRun();
417-
if (isInBrowser && shouldReport) {
418-
setTimeout(() => this.start(), 4000);
439+
this.isReady = true;
440+
if (isInBrowser) {
441+
globalThis.dispatchEvent(new Event("JetStreamReady"));
442+
if (shouldReport) {
443+
setTimeout(() => this.start(), 4000);
444+
}
419445
}
420446
}
421447

@@ -441,7 +467,7 @@ class Driver {
441467
// If we've failed to prefetch resources even after a sequential 1 by 1 retry,
442468
// then fail out early rather than letting subtests fail with a hang.
443469
window.allIsGood = false;
444-
throw new Error("Fetch failed");
470+
throw new Error("Fetch failed");
445471
}
446472
}
447473

@@ -467,7 +493,7 @@ class Driver {
467493
}
468494
}
469495

470-
resultsJSON()
496+
resultsObject()
471497
{
472498
let results = {};
473499
for (let benchmark of this.benchmarks) {
@@ -486,8 +512,13 @@ class Driver {
486512
}
487513

488514
results = {"JetStream3.0": {"metrics" : {"Score" : ["Geometric"]}, "tests" : results}};
515+
return results;
489516

490-
return JSON.stringify(results);
517+
}
518+
519+
resultsJSON()
520+
{
521+
return JSON.stringify(this.resultsObject());
491522
}
492523

493524
dumpJSONResultsIfNeeded()
@@ -525,6 +556,7 @@ class Benchmark {
525556
{
526557
this.plan = plan;
527558
this.iterations = getIterationCount(plan);
559+
console.log({name:this.name, iterations:this.iterations})
528560
this.isAsync = !!plan.isAsync;
529561

530562
this.scripts = null;
@@ -547,11 +579,10 @@ class Benchmark {
547579
let start = performance.now();
548580
__benchmark.runIteration();
549581
let end = performance.now();
550-
551582
results.push(Math.max(1, end - start));
552583
}
553584
if (__benchmark.validate)
554-
__benchmark.validate();
585+
__benchmark.validate(${this.iterations});
555586
top.currentResolve(results);`;
556587
}
557588

@@ -804,7 +835,7 @@ class Benchmark {
804835

805836
if (!blobData.blob) {
806837
window.allIsGood = false;
807-
throw new Error("Fetch failed");
838+
throw new Error("Fetch failed");
808839
}
809840

810841
return !counter.failedPreloadResources && counter.loadedResources == counter.totalResources;
@@ -858,11 +889,10 @@ class Benchmark {
858889
scoreIdentifiers() { throw new Error("Must be implemented by subclasses"); }
859890

860891
updateUIBeforeRun() {
861-
if (!isInBrowser) {
862-
if (!dumpJSONResults)
863-
console.log(`Running ${this.name}:`);
892+
if (!dumpJSONResults)
893+
console.log(`Running ${this.name}:`);
894+
if (!isInBrowser)
864895
return;
865-
}
866896

867897
let containerUI = document.getElementById("results");
868898
let resultsBenchmarkUI = document.getElementById(`benchmark-${this.name}`);
@@ -947,7 +977,6 @@ class DefaultBenchmark extends Benchmark {
947977
document.getElementById(worst4ID(this)).innerHTML = uiFriendlyNumber(this.worst4);
948978
document.getElementById(avgID(this)).innerHTML = uiFriendlyNumber(this.average);
949979
document.getElementById(scoreID(this)).innerHTML = uiFriendlyNumber(this.score);
950-
return;
951980
}
952981

953982
if (dumpJSONResults)
@@ -979,7 +1008,7 @@ class AsyncBenchmark extends DefaultBenchmark {
9791008
results.push(Math.max(1, end - start));
9801009
}
9811010
if (__benchmark.validate)
982-
__benchmark.validate();
1011+
__benchmark.validate(${this.iterations});
9831012
top.currentResolve(results);
9841013
}
9851014
doRun().catch((error) => { top.currentReject(error); });`
@@ -1045,7 +1074,6 @@ class WSLBenchmark extends Benchmark {
10451074
document.getElementById("wsl-stdlib-score").innerHTML = uiFriendlyNumber(this.stdlib);
10461075
document.getElementById("wsl-tests-score").innerHTML = uiFriendlyNumber(this.mainRun);
10471076
document.getElementById("wsl-score-score").innerHTML = uiFriendlyNumber(this.score);
1048-
return;
10491077
}
10501078

10511079
if (dumpJSONResults)
@@ -1226,7 +1254,6 @@ class WasmBenchmark extends Benchmark {
12261254
document.getElementById(this.startupID).innerHTML = uiFriendlyNumber(this.startupTime);
12271255
document.getElementById(this.runID).innerHTML = uiFriendlyNumber(this.runTime);
12281256
document.getElementById(this.scoreID).innerHTML = uiFriendlyNumber(this.score);
1229-
return;
12301257
}
12311258

12321259
if (dumpJSONResults)

RexBench/UniPoker/benchmark.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ class Benchmark {
3939
playHands(this._players);
4040
}
4141

42-
validate()
42+
validate(iterations)
4343
{
44+
if (!iterations)
45+
throw "Invalid iterations"
46+
const playerExpectations = getPlayerExpectations(iterations)
4447
if (this._players.length != playerExpectations.length)
4548
throw "Expect " + playerExpectations.length + ", but actually have " + this._players.length;
4649
if (isInBrowser) {

RexBench/UniPoker/expected.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@
2424
*/
2525
"use strict";
2626

27+
const defaultIterationCount = 120;
28+
2729
class PlayerExpectation
2830
{
29-
constructor(wins, handTypeCounts)
31+
constructor(iterations, wins, handTypeCounts)
3032
{
31-
this._wins = wins;
32-
this._handTypeCounts = handTypeCounts;
33+
const factor = iterations / defaultIterationCount;
34+
this._wins = wins * factor;
35+
this._handTypeCounts = handTypeCounts.map(each => each * factor);
3336
}
3437

3538
validate(player)
@@ -62,10 +65,13 @@ PlayerExpectation._handTypes = [
6265
"Straight Flushes",
6366
"Royal Flushes"
6467
];
65-
66-
var playerExpectations = [];
6768

68-
playerExpectations.push(new PlayerExpectation(60120, [120600, 102000, 10080, 5040, 1440, 360, 480, 0, 0, 0]));
69-
playerExpectations.push(new PlayerExpectation(60480, [120360, 99600, 11760, 6120, 1200, 360, 480, 120, 0, 0]));
70-
playerExpectations.push(new PlayerExpectation(61440, [121200, 99720, 11040, 6120, 1080, 480, 360, 0, 0, 0]));
71-
playerExpectations.push(new PlayerExpectation(57960, [121320, 100440, 11040, 5760, 840, 480, 120, 0, 0, 0]));
69+
70+
function getPlayerExpectations(iterations) {
71+
const playerExpectations = [];
72+
playerExpectations.push(new PlayerExpectation(iterations, 60120, [120600, 102000, 10080, 5040, 1440, 360, 480, 0, 0, 0]));
73+
playerExpectations.push(new PlayerExpectation(iterations, 60480, [120360, 99600, 11760, 6120, 1200, 360, 480, 120, 0, 0]));
74+
playerExpectations.push(new PlayerExpectation(iterations, 61440, [121200, 99720, 11040, 6120, 1080, 480, 360, 0, 0, 0]));
75+
playerExpectations.push(new PlayerExpectation(iterations, 57960, [121320, 100440, 11040, 5760, 840, 480, 120, 0, 0, 0]));
76+
return playerExpectations;
77+
}

0 commit comments

Comments
 (0)