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

feat: add arguments in cli to support methods queryparam, repeat example #6022

Merged
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {
customElement,
FASTElement,
html,
observable,
repeat,
ViewTemplate,
} from "@microsoft/fast-element";
import { data, RandomItem } from "../../../utils/index.js";
import { queryParams } from "../../../utils/query-params.js";

const { method } = queryParams;

const templates = {
repeat: html<XApp>`
${repeat(
x => x.items,
html<RandomItem>`
<li>${x => x.label}</li>
`
)}
`,
repeatNoRecycle: html<XApp>`
${(repeat(
x => x.items,
html<RandomItem>`
<li>${x => x.label}</li>
`
),
{ recycle: false })}
`,
} as any;

@customElement({
name: "x-app",
template: html<XApp>`
<div>
${x => x.getTemplateByMethod()}
</div>
`,
})
class XApp extends FASTElement {
@observable items: RandomItem[] = data;
@observable method: string = <string>method;

getTemplateByMethod() {
return templates[this.method] as ViewTemplate;
}
}
5 changes: 4 additions & 1 deletion packages/utilities/fast-benchmarks/scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ const errMessage = chalk.hex("#ffb638");
program
.option("-l, --library <name>", "run benchmarks in <name> library")
.option("-b, --benchmark <name>", "run the benchmark: <name>")
.option("-m, --memory", "only display memory consumption results")
.option(
"-v, --versions [versions...]",
"specify available versions, you can also use 'local' or 'master' that would point to github branches"
)
.option(
"-m, --methods [methods...]",
"specify different methods through url query params for one version you want to benchmark"
)
.option(
"-lb, --localBenchFile <name>",
"specify the html file you want your local version to use, only valid if 'local' is one of the versions you passed in"
Expand Down
46 changes: 23 additions & 23 deletions packages/utilities/fast-benchmarks/scripts/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ const libraryDependencies = {
},
};
async function generateBenchmarks(
{ library, benchmark, versions, memory },
{ library, benchmark, versions, methods },
operationProps,
localProps
) {
Expand All @@ -179,16 +179,21 @@ async function generateBenchmarks(
/** @type {ConfigFile["benchmarks"]} */

const benchmarks = [];
const memoryBenchmarks = [];
const browser = {
name: "chrome",
headless: true,
addArguments: ["--js-flags=--expose-gc", "--enable-precise-memory-info"],
};
const measurement = [
{
mode: "performance",
entryName: operation,
},
{
name: "usedJSHeapSize",
mode: "expression",
expression: "window.usedJSHeapSize",
},
];

versions.forEach(version => {
Expand Down Expand Up @@ -240,28 +245,23 @@ async function generateBenchmarks(
};
}

//adjust some settings to separately report memory benchmark results
const memoryBench = JSON.parse(JSON.stringify(bench));
const memoryMeasurement = [
{
name: "usedJSHeapSize",
mode: "expression",
expression: "window.usedJSHeapSize",
},
];
memoryBench.name = `${name}-memory`;
memoryBench.measurement = memoryMeasurement;
memoryBench.browser.addArguments = [
"--js-flags=--expose-gc",
"--enable-precise-memory-info",
];
memoryBenchmarks.push(memoryBench);
if (methods.length > 0) {
methods.forEach(method => {
const fullUrl = `${url}?method=${method}`;

if (!memory) benchmarks.push(bench);
const bench = {
url: fullUrl,
browser,
name: `${name}-${method}`,
measurement,
};
benchmarks.push(bench);
});
} else {
benchmarks.push(bench);
}
});

tachoData[`${operation}-memory`] = memoryBenchmarks;
if (!memory) tachoData[operation] = benchmarks;
tachoData[operation] = benchmarks;
});

return tachoData;
Expand All @@ -282,7 +282,7 @@ async function generateConfig(fileName, benchmarksHash) {
// Tachometer default is 50, but locally let's only do 10
sampleSize: 30,
// Tachometer default is 3 minutes, but let's shrink it to 1 here to save some
timeout: 1,
timeout: 0,
autoSampleConditions: ["0%", "10%"],
};

Expand Down