Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add complexity param #430

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
20 changes: 18 additions & 2 deletions resources/developer-mode.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function createDeveloperModeContainer() {
settings.append(createUIForWarmupSuite());
settings.append(createUIForWarmupBeforeSync());
settings.append(createUIForSyncStepDelay());
settings.append(createUIForComplexity());

content.append(document.createElement("hr"));
content.append(settings);
Expand Down Expand Up @@ -101,11 +102,21 @@ function createUIForSyncStepDelay() {
return label;
}

function createTimeRangeUI(labelText, initialValue, unit = "ms", min = 0, max = 1000) {
function createUIForComplexity() {
const { range, label } = createTimeRangeUI("Relative complexity", params.complexity, "x", 0, 10, 0.01);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that rather than a float, maybe this can be an integer between 1 and 100, with 50 being the default?

Then later you can divide this number by 50 to get the multiplier.
And you can cut down a lot of the changes.

But this is merely a suggestion, I'm also happy with what you did.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda prefer a normalized float value, aiming quite literaly at a complexity-factor, 2x => it should run roughly twice as slow.

range.onchange = () => {
params.complexity = Number(range.value);
updateURL();
};
return label;
}

function createTimeRangeUI(labelText, initialValue, unit = "ms", min = 0, max = 1000, step = 1) {
const range = document.createElement("input");
range.type = "range";
range.min = min;
range.max = max;
range.step = step;
range.value = initialValue;

const rangeValueAndUnit = document.createElement("span");
Expand Down Expand Up @@ -268,7 +279,7 @@ function updateURL() {
}
}

if (params.measurementMethod !== "raf")
if (params.measurementMethod !== defaultParams.measurementMethod)
url.searchParams.set("measurementMethod", "timer");
else
url.searchParams.delete("measurementMethod");
Expand All @@ -281,6 +292,11 @@ function updateURL() {
url.searchParams.delete(paramKey);
}

if (params.complexity !== defaultParams.complexity)
url.searchParams.set("complexity", params.complexity);
else
url.searchParams.delete("complexity");

// Only push state if changed
url.search = decodeURIComponent(url.search);
if (url.href !== window.location.href)
Expand Down
6 changes: 3 additions & 3 deletions resources/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class MainBenchmarkClient {
this._showSection(window.location.hash);
}

start() {
if (this._startBenchmark())
async start() {
if (await this._startBenchmark())
this._showSection("#running");
}

_startBenchmark() {
async _startBenchmark() {
if (this._isRunning)
return false;

Expand Down
20 changes: 19 additions & 1 deletion resources/params.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class Params {
// "generate": generate a random seed
// <integer>: use the provided integer as a seed
shuffleSeed = "off";
// Param to tweak the relative complexity of all suites.
// The default is 1.0, and for suites supporting this param, the duration
// roughly scales wit the complexity.
complexity = 1.0;

constructor(searchParams = undefined) {
if (searchParams)
Expand All @@ -35,8 +39,15 @@ class Params {
}
}

_parseInt(value, errorMessage) {
_parseNumber(value, errorMessage) {
const number = Number(value);
if (!Number.isFinite(number) && errorMessage)
throw new Error(`Invalid ${errorMessage} param: '${value}', expected Number.`);
return number;
}

_parseInt(value, errorMessage) {
const number = this._parseNumber(value);
if (!Number.isInteger(number) && errorMessage)
throw new Error(`Invalid ${errorMessage} param: '${value}', expected int.`);
return parseInt(number);
Expand Down Expand Up @@ -122,6 +133,13 @@ class Params {
searchParams.delete("shuffleSeed");
}

if (searchParams.has("complexity")) {
this.complexity = this._parseNumber(searchParams.get("complexity"));
if (this.complexity <= 0)
throw new Error(`Invalid complexity value: ${this.complexity}, must be > 0.0`);
searchParams.delete("complexity");
}

const unused = Array.from(searchParams.keys());
if (unused.length > 0)
console.error("Got unused search params", unused);
Expand Down
Loading
Loading