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
Draft
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
8 changes: 8 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ <h1>Score</h1>
<div class="section-grid">
<h1 class="section-header">Detailed Results</h1>
<div class="section-content all-metric-results">
<div class="non-standard-params">
<h2>Non-standard Parameters</h2>
<p>
Speedometer ran with non-standard parameters.<br />
The results are likely not comparable to default runs.
</p>
<table id="non-standard-params-table"></table>
</div>
<div class="aggregated-metric-result">
<h2>Aggregate Metric</h2>
<div id="geomean-chart"></div>
Expand Down
15 changes: 13 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 @@ -280,7 +291,7 @@ function updateURL() {
}
}

const defaultParamKeys = ["measurementMethod", "iterationCount", "useWarmupSuite", "warmupBeforeSync", "waitBeforeSync"];
const defaultParamKeys = ["measurementMethod", "iterationCount", "useWarmupSuite", "warmupBeforeSync", "waitBeforeSync", "complexity"];
for (const paramKey of defaultParamKeys) {
if (params[paramKey] !== defaultParams[paramKey])
url.searchParams.set(paramKey, params[paramKey]);
Expand Down
38 changes: 34 additions & 4 deletions resources/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,40 @@ section#instructions .section-content > * {
flex-direction: column;
}

section#details h1 {
margin-bottom: 10px;
}

section#details .non-standard-params {
display: none;
text-align: center;
margin-bottom: 2em;
}

section#details .non-standard-params h2 {
color: var(--highlight);
}

#non-standard-params-table {
border-collapse: collapse;
text-align: left;
display: inline-block;
}
#non-standard-params-table tr {
padding: 2px;
}

#non-standard-params-table thead th {
border-bottom: 1px solid var(--foreground);
padding: 0.1em 0.2em;
}

#non-standard-params-table tbody th {
font-weight: normal;
text-align: left;
padding: 0.1em 0.2em;
}

section#details .all-metric-results {
flex: auto;
overflow-y: auto;
Expand All @@ -513,10 +547,6 @@ section#details .arithmetic-mean > label {
margin-right: 10px;
}

section#details h1 {
margin-bottom: 10px;
}

section#details .metric {
margin: 0px 0 10px 0;
display: inline-block;
Expand Down
31 changes: 30 additions & 1 deletion resources/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BenchmarkRunner } from "./benchmark-runner.mjs";
import * as Statistics from "./statistics.mjs";
import { Suites } from "./tests.mjs";
import { renderMetricView } from "./metric-ui.mjs";
import { params } from "./params.mjs";
import { defaultParams, params } from "./params.mjs";
import { createDeveloperModeContainer } from "./developer-mode.mjs";

// FIXME(camillobruni): Add base class
Expand Down Expand Up @@ -245,6 +245,7 @@ class MainBenchmarkClient {
}

_populateDetailedResults(metrics) {
this._populateNonStandardParams();
const trackHeight = 24;
document.documentElement.style.setProperty("--metrics-line-height", `${trackHeight}px`);
const plotWidth = (params.viewport.width - 120) / 2;
Expand Down Expand Up @@ -292,6 +293,34 @@ class MainBenchmarkClient {
csvLink.setAttribute("download", `${filePrefix}.csv`);
}

_populateNonStandardParams() {
if (params === defaultParams)
return;
const paramsDiff = [];
const usedSearchparams = params.toSearchParams();
const defaultSearchParams = defaultParams.toSearchParams();
for (const [key, value] of usedSearchparams.entries()) {
const defaultValue = defaultSearchParams.get(key);
if (value !== defaultValue)
paramsDiff.push({ key, value, defaultValue });
}
if (paramsDiff.length === 0)
return;
let body = "";
for (const { key, value, defaultValue } of paramsDiff)
body += `<tr><th>${key}</th><th>${value}</th><th>${defaultValue}</th></tr>`;
const table = document.getElementById("non-standard-params-table");
table.innerHTML = `<thead>
<tr>
<th>Param</th>
<th>Value</th>
<th>Default</th>
</tr>
</thead>
<tbody>${body}</tbody>`;
document.querySelector(".non-standard-params").style.display = "block";
}

prepareUI() {
window.addEventListener("hashchange", this._hashChangeHandler.bind(this));
window.addEventListener("resize", this._resizeScreeHandler.bind(this));
Expand Down
38 changes: 29 additions & 9 deletions 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 All @@ -130,18 +148,20 @@ class Params {
toSearchParams() {
const rawParams = { ...this };
rawParams["viewport"] = `${this.viewport.width}x${this.viewport.height}`;
return new URLSearchParams(rawParams).toString();
return new URLSearchParams(rawParams);
}
}

export const defaultParams = new Params();

const searchParams = new URLSearchParams(window.location.search);
let maybeCustomParams = new Params();
try {
maybeCustomParams = new Params(searchParams);
} catch (e) {
console.error("Invalid URL Param", e, "\nUsing defaults as fallback:", maybeCustomParams);
alert(`Invalid URL Param: ${e}`);
let maybeCustomParams = defaultParams;
if (window.location.search) {
const searchParams = new URLSearchParams(window.location.search);
try {
maybeCustomParams = new Params(searchParams);
} catch (e) {
console.error("Invalid URL Param", e, "\nUsing defaults as fallback:", maybeCustomParams);
alert(`Invalid URL Param: ${e}`);
}
}
export const params = maybeCustomParams;
Loading
Loading