mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 06:20:02 -04:00
add overhead measurement
This commit is contained in:
parent
6cec47b891
commit
c54929198d
2 changed files with 5 additions and 4 deletions
|
@ -35,7 +35,7 @@ export class ScramjetController {
|
||||||
cleanerrors: false,
|
cleanerrors: false,
|
||||||
scramitize: false,
|
scramitize: false,
|
||||||
sourcemaps: false,
|
sourcemaps: false,
|
||||||
rewriterLogs: false,
|
rewriterLogs: true,
|
||||||
},
|
},
|
||||||
siteFlags: {},
|
siteFlags: {},
|
||||||
codec: {
|
codec: {
|
||||||
|
|
|
@ -25,6 +25,7 @@ function rewriteJsWrapper(
|
||||||
meta: URLMeta
|
meta: URLMeta
|
||||||
): string | ArrayBuffer {
|
): string | ArrayBuffer {
|
||||||
let out: RewriterOutput;
|
let out: RewriterOutput;
|
||||||
|
const before = performance.now();
|
||||||
if (typeof input === "string") {
|
if (typeof input === "string") {
|
||||||
out = rewrite_js(input, meta.base.href, url || "(unknown)", $scramjet);
|
out = rewrite_js(input, meta.base.href, url || "(unknown)", $scramjet);
|
||||||
} else {
|
} else {
|
||||||
|
@ -35,16 +36,15 @@ function rewriteJsWrapper(
|
||||||
$scramjet
|
$scramjet
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
const after = performance.now();
|
||||||
const { js, errors, duration } = out;
|
const { js, errors, duration } = out;
|
||||||
|
|
||||||
// TODO: maybe make this a scram flag?
|
|
||||||
if (flagEnabled("rewriterLogs", meta.base)) {
|
if (flagEnabled("rewriterLogs", meta.base)) {
|
||||||
for (const error of errors) {
|
for (const error of errors) {
|
||||||
console.error("oxc parse error", error);
|
console.error("oxc parse error", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: maybe make this a scram flag?
|
|
||||||
if (flagEnabled("rewriterLogs", meta.base)) {
|
if (flagEnabled("rewriterLogs", meta.base)) {
|
||||||
let timespan: string;
|
let timespan: string;
|
||||||
if (duration < 1n) {
|
if (duration < 1n) {
|
||||||
|
@ -54,8 +54,9 @@ function rewriteJsWrapper(
|
||||||
} else {
|
} else {
|
||||||
timespan = "really slow";
|
timespan = "really slow";
|
||||||
}
|
}
|
||||||
|
const overhead = (after - before - Number(duration)).toFixed(2);
|
||||||
console.log(
|
console.log(
|
||||||
`oxc rewrite for "${url || "(unknown)"}" was ${timespan} (${duration}ms)`
|
`oxc rewrite for "${url || "(unknown)"}" was ${timespan} (${duration}ms; ${overhead}ms overhead)`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue