Skip to content

Instantly share code, notes, and snippets.

@rubys
Created June 28, 2018 19:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rubys/4798e9c5418814c8810b295dfb5cbbaa to your computer and use it in GitHub Desktop.
Save rubys/4798e9c5418814c8810b295dfb5cbbaa to your computer and use it in GitHub Desktop.
Instrumenting tools/doc/html.js for performance analysis
diff --git a/tools/doc/html.js b/tools/doc/html.js
index 974eab769c..b4153c4eee 100644
--- a/tools/doc/html.js
+++ b/tools/doc/html.js
@@ -53,6 +53,8 @@ function navClasses() {
}
}
+let start = new Date().getTime();
+
const gtocPath = path.join(docPath, 'api', '_toc.md');
const gtocMD = fs.readFileSync(gtocPath, 'utf8').replace(/^@\/\/.*$/gm, '');
const gtocHTML = unified()
@@ -63,23 +65,46 @@ const gtocHTML = unified()
.use(html)
.processSync(gtocMD).toString();
+const gtoc_time = new Date().getTime();
+let times = {gtoc: gtoc_time - start};
+start = gtoc_time;
+
const templatePath = path.join(docPath, 'template.html');
const template = fs.readFileSync(templatePath, 'utf8');
+function timestamp({ name }) {
+ return (tree, file) => {
+ const ts = new Date().getTime();
+ times[name] = ts - start;
+ start = ts;
+ }
+}
+
function toHTML({ input, filename, nodeVersion, analytics }, cb) {
filename = path.basename(filename, '.md');
const content = unified()
.use(markdown)
+ .use(timestamp.bind({}), { name : 'parse' })
.use(firstHeader)
+ .use(timestamp.bind({}), { name : 'firstHeader' })
.use(preprocessText)
+ .use(timestamp.bind({}), { name : 'preprocessText' })
.use(preprocessElements, { filename: filename })
+ .use(timestamp.bind({}), { name : 'preprocessElements' })
.use(buildToc, { filename: filename })
+ .use(timestamp.bind({}), { name : 'buildToc' })
.use(remark2rehype, { allowDangerousHTML: true })
+ .use(timestamp.bind({}), { name : 'remark2rehype' })
.use(raw)
+ .use(timestamp.bind({}), { name : 'raw' })
.use(html)
.processSync(input);
+times.serialize = new Date().getTime() - start;
+
+console.error(times);
+
const id = filename.replace(/\W+/g, '-');
let HTML = template.replace('__ID__', id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment