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

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 48 additions & 17 deletions resources/developer-mode.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Suites, Tags } from "./tests.mjs";
import { Suites, Tags, handleComplexityChange } from "./tests.mjs";
import { params, defaultParams } from "./shared/params.mjs";

export function createDeveloperModeContainer() {
Expand All @@ -21,6 +21,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 @@ -51,7 +52,7 @@ function createCheckboxUI(labelValue, initialValue, paramsUpdateCallback) {
checkbox.checked = !!initialValue;
checkbox.onchange = () => {
paramsUpdateCallback(checkbox.checked);
updateURL();
handleParamsChange();
};

const label = document.createElement("label");
Expand All @@ -61,23 +62,48 @@ function createCheckboxUI(labelValue, initialValue, paramsUpdateCallback) {
}

function createUIForIterationCount() {
return createTimeRangeUI("Iterations: ", "iterationCount", "#", 1, 200);
return createLinearRangeUI("Iterations: ", "iterationCount", "#", 1, 200);
}

function createUIForWarmupBeforeSync() {
return createTimeRangeUI("Warmup time: ", "warmupBeforeSync");
return createLinearRangeUI("Warmup time: ", "warmupBeforeSync");
}

function createUIForSyncStepDelay() {
return createTimeRangeUI("Sync step delay: ", "waitBeforeSync");
return createLinearRangeUI("Sync step delay: ", "waitBeforeSync");
}

function createTimeRangeUI(labelText, paramKey, unit = "ms", min = 0, max = 1000) {
const range = document.createElement("input");
range.type = "range";
function createUIForComplexity() {
return createExpRangeUI("Relative complexity: ", "complexity", "x", 0.01, 100, 0.01);
}

function createLinearRangeUI(labelText, paramKey, unit = "ms", min = 0, max = 1000, step = 1) {
const linearMap = (value) => value;
const { range, label } = createTimeRangeUI(labelText, paramKey, unit, linearMap, 0);
range.min = min;
range.max = max;
range.step = step;
range.value = params[paramKey];
return label;
}

function createExpRangeUI(labelText, paramKey, unit = "ms", min = 0, max = 1000, step = 1) {
const defaultValue = defaultParams[paramKey];
const initialValue = params[paramKey];
const b = defaultValue - 1;
const a = -Math.log(min - b);
const logMap = (value) => Math.round((Math.exp(value * a) + b) / step) * step;
const { range, label } = createTimeRangeUI(labelText, paramKey, unit, logMap, 2);
range.min = -1;
range.max = Math.log(max - b) / a;
range.step = 0.01;
range.value = Math.log(initialValue - b) / a;
return label;
}

function createTimeRangeUI(labelText, paramKey, unit = "ms", map, decimals) {
const range = document.createElement("input");
range.type = "range";

const rangeValueAndUnit = document.createElement("span");
rangeValueAndUnit.className = "range-label-data";
Expand All @@ -90,14 +116,14 @@ function createTimeRangeUI(labelText, paramKey, unit = "ms", min = 0, max = 1000
label.append(span(labelText), range, rangeValueAndUnit);

range.oninput = () => {
rangeValue.textContent = range.value;
rangeValue.textContent = map(Number(range.value)).toFixed(decimals);
};
range.onchange = () => {
params[paramKey] = parseInt(range.value);
updateURL();
params[paramKey] = map(Number(range.value));
handleParamsChange();
};

return label;
return { range, label };
}

function createUIForSuites() {
Expand All @@ -120,7 +146,7 @@ function createUIForSuites() {
checkbox.checked = !suite.disabled;
checkbox.onchange = () => {
suite.disabled = !checkbox.checked;
updateURL();
handleParamsChange();
};
checkboxes.push(checkbox);

Expand Down Expand Up @@ -155,7 +181,7 @@ function createSuitesGlobalSelectButtons(setSuiteEnabled) {
for (let suiteIndex = 0; suiteIndex < Suites.length; suiteIndex++)
setSuiteEnabled(suiteIndex, true);

updateURL();
handleParamsChange();
};
buttons.appendChild(button);

Expand All @@ -165,7 +191,7 @@ function createSuitesGlobalSelectButtons(setSuiteEnabled) {
for (let suiteIndex = 0; suiteIndex < Suites.length; suiteIndex++)
setSuiteEnabled(suiteIndex, false);

updateURL();
handleParamsChange();
};
buttons.appendChild(button);
return buttons;
Expand Down Expand Up @@ -201,7 +227,7 @@ function createSuitesTagsButton(setSuiteEnabled) {
continue;
setSuiteEnabled(suiteIndex, enabled);
}
updateURL();
handleParamsChange();
};
buttons.appendChild(button);
}
Expand All @@ -226,6 +252,11 @@ function createUIForRun() {
return buttons;
}

function handleParamsChange() {
updateURL();
handleComplexityChange();
}

function updateURL() {
const url = new URL(window.location.href);

Expand Down Expand Up @@ -255,7 +286,7 @@ function updateURL() {
}
}

const defaultParamKeys = ["iterationCount", "useWarmupSuite", "warmupBeforeSync", "waitBeforeSync"];
const defaultParamKeys = ["iterationCount", "useWarmupSuite", "warmupBeforeSync", "waitBeforeSync", "complexity"];
for (const paramKey of defaultParamKeys) {
if (params[paramKey] !== defaultParams[paramKey])
url.searchParams.set(paramKey, params[paramKey]);
Expand Down
2 changes: 1 addition & 1 deletion resources/newssite/news-next/dist/404.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="preload" href="./_next/static/css/a0dca1379a01e5cf.css" as="style"/><link rel="stylesheet" href="./_next/static/css/a0dca1379a01e5cf.css" data-n-g=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="./_next/static/chunks/polyfills-c67a75d1b6f99dc8.js"></script><script src="./_next/static/chunks/webpack-e50e9853db18b759.js" defer=""></script><script src="./_next/static/chunks/framework-2c79e2a64abdb08b.js" defer=""></script><script src="./_next/static/chunks/main-2ba37e62325cc71b.js" defer=""></script><script src="./_next/static/chunks/pages/_app-4fe6038a10d156ec.js" defer=""></script><script src="./_next/static/chunks/pages/_error-54de1933a164a1ff.js" defer=""></script><script src="./_next/static/slmX88Sy3MO0SLK8cVHnz/_buildManifest.js" defer=""></script><script src="./_next/static/slmX88Sy3MO0SLK8cVHnz/_ssgManifest.js" defer=""></script></head><body><div id="__next"></div><div id="settings-container"></div><div id="notifications-container"></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"statusCode":404}},"page":"/_error","query":{},"buildId":"slmX88Sy3MO0SLK8cVHnz","assetPrefix":".","nextExport":true,"isFallback":false,"gip":true,"scriptLoader":[]}</script></body></html>
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="preload" href="./_next/static/css/a0dca1379a01e5cf.css" as="style"/><link rel="stylesheet" href="./_next/static/css/a0dca1379a01e5cf.css" data-n-g=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="./_next/static/chunks/polyfills-c67a75d1b6f99dc8.js"></script><script src="./_next/static/chunks/webpack-e50e9853db18b759.js" defer=""></script><script src="./_next/static/chunks/framework-2c79e2a64abdb08b.js" defer=""></script><script src="./_next/static/chunks/main-2ba37e62325cc71b.js" defer=""></script><script src="./_next/static/chunks/pages/_app-4fe6038a10d156ec.js" defer=""></script><script src="./_next/static/chunks/pages/_error-54de1933a164a1ff.js" defer=""></script><script src="./_next/static/gfCjx3iuMQPhPYoF7VR26/_buildManifest.js" defer=""></script><script src="./_next/static/gfCjx3iuMQPhPYoF7VR26/_ssgManifest.js" defer=""></script></head><body><div id="__next"></div><div id="settings-container"></div><div id="notifications-container"></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"statusCode":404}},"page":"/_error","query":{},"buildId":"gfCjx3iuMQPhPYoF7VR26","assetPrefix":".","nextExport":true,"isFallback":false,"gip":true,"scriptLoader":[]}</script></body></html>
2 changes: 1 addition & 1 deletion resources/newssite/news-next/dist/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="preload" href="./_next/static/css/a0dca1379a01e5cf.css" as="style"/><link rel="stylesheet" href="./_next/static/css/a0dca1379a01e5cf.css" data-n-g=""/><link rel="preload" href="./_next/static/css/69253d842fd3fbfd.css" as="style"/><link rel="stylesheet" href="./_next/static/css/69253d842fd3fbfd.css" data-n-p=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="./_next/static/chunks/polyfills-c67a75d1b6f99dc8.js"></script><script src="./_next/static/chunks/webpack-e50e9853db18b759.js" defer=""></script><script src="./_next/static/chunks/framework-2c79e2a64abdb08b.js" defer=""></script><script src="./_next/static/chunks/main-2ba37e62325cc71b.js" defer=""></script><script src="./_next/static/chunks/pages/_app-4fe6038a10d156ec.js" defer=""></script><script src="./_next/static/chunks/553-29fd8c03a09c7b37.js" defer=""></script><script src="./_next/static/chunks/pages/index-7052462c4e106c39.js" defer=""></script><script src="./_next/static/slmX88Sy3MO0SLK8cVHnz/_buildManifest.js" defer=""></script><script src="./_next/static/slmX88Sy3MO0SLK8cVHnz/_ssgManifest.js" defer=""></script></head><body><div id="__next"></div><div id="settings-container"></div><div id="notifications-container"></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{}},"page":"/","query":{},"buildId":"slmX88Sy3MO0SLK8cVHnz","assetPrefix":".","nextExport":true,"autoExport":true,"isFallback":false,"scriptLoader":[]}</script></body></html>
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="preload" href="./_next/static/css/a0dca1379a01e5cf.css" as="style"/><link rel="stylesheet" href="./_next/static/css/a0dca1379a01e5cf.css" data-n-g=""/><link rel="preload" href="./_next/static/css/69253d842fd3fbfd.css" as="style"/><link rel="stylesheet" href="./_next/static/css/69253d842fd3fbfd.css" data-n-p=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="./_next/static/chunks/polyfills-c67a75d1b6f99dc8.js"></script><script src="./_next/static/chunks/webpack-e50e9853db18b759.js" defer=""></script><script src="./_next/static/chunks/framework-2c79e2a64abdb08b.js" defer=""></script><script src="./_next/static/chunks/main-2ba37e62325cc71b.js" defer=""></script><script src="./_next/static/chunks/pages/_app-4fe6038a10d156ec.js" defer=""></script><script src="./_next/static/chunks/553-29fd8c03a09c7b37.js" defer=""></script><script src="./_next/static/chunks/pages/index-7052462c4e106c39.js" defer=""></script><script src="./_next/static/gfCjx3iuMQPhPYoF7VR26/_buildManifest.js" defer=""></script><script src="./_next/static/gfCjx3iuMQPhPYoF7VR26/_ssgManifest.js" defer=""></script></head><body><div id="__next"></div><div id="settings-container"></div><div id="notifications-container"></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{}},"page":"/","query":{},"buildId":"gfCjx3iuMQPhPYoF7VR26","assetPrefix":".","nextExport":true,"autoExport":true,"isFallback":false,"scriptLoader":[]}</script></body></html>
20 changes: 19 additions & 1 deletion resources/shared/params.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export 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 @@ export 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 All @@ -55,6 +66,13 @@ export class Params {
this.measurementMethod = this._parseMeasurementMethod(searchParams);
this.shuffleSeed = this._parseShuffleSeed(searchParams);

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