Disclaimer: The following snippet can run slowly and/or lock up in most browsers due to a performance issue in the running library. However this illustrates an oddity that I can’t seem to resolve.
Question: Why in the below snippet is there such a significant difference in timing between console.time and window.performance.measure?
import { unified } from "unified";
import remarkParse from "remark-parse";
import remarkRehype from "remark-rehype";
import rehypeStringify from "rehype-stringify";
const sourceMarkdown = `
1${" ".repeat(75000)}2
`;
document.getElementById("source").innerHTML = sourceMarkdown;
try {
console.time("unified-pipeline");
window.performance.mark("unified-pipeline");
unified()
.use(remarkParse)
.use(remarkRehype)
.use(rehypeStringify)
.process(sourceMarkdown)
.then((file) => {
document.getElementById(
"result"
).contentWindow.document.body.innerHTML = String(file);
console.timeEnd("unified-pipeline");
console.log(window.performance.measure("unified-pipeline"));
});
} catch (err) {
document.getElementById("error").innerHTML = err;
}