Skip to content

Commit

Permalink
add overhead measurement
Browse files Browse the repository at this point in the history
  • Loading branch information
r58Playz committed Nov 12, 2024
1 parent 6cec47b commit c549291
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/controller/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class ScramjetController {
cleanerrors: false,
scramitize: false,
sourcemaps: false,
rewriterLogs: false,
rewriterLogs: true,
},
siteFlags: {},
codec: {
Expand Down
7 changes: 4 additions & 3 deletions src/shared/rewriters/js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function rewriteJsWrapper(
meta: URLMeta
): string | ArrayBuffer {
let out: RewriterOutput;
const before = performance.now();
if (typeof input === "string") {
out = rewrite_js(input, meta.base.href, url || "(unknown)", $scramjet);
} else {
Expand All @@ -35,16 +36,15 @@ function rewriteJsWrapper(
$scramjet
);
}
const after = performance.now();
const { js, errors, duration } = out;

// TODO: maybe make this a scram flag?
if (flagEnabled("rewriterLogs", meta.base)) {
for (const error of errors) {
console.error("oxc parse error", error);
}
}

// TODO: maybe make this a scram flag?
if (flagEnabled("rewriterLogs", meta.base)) {
let timespan: string;
if (duration < 1n) {
Expand All @@ -54,8 +54,9 @@ function rewriteJsWrapper(
} else {
timespan = "really slow";
}
const overhead = (after - before - Number(duration)).toFixed(2);
console.log(
`oxc rewrite for "${url || "(unknown)"}" was ${timespan} (${duration}ms)`
`oxc rewrite for "${url || "(unknown)"}" was ${timespan} (${duration}ms; ${overhead}ms overhead)`
);
}

Expand Down

0 comments on commit c549291

Please sign in to comment.