Skip to content

Commit

Permalink
[internal] add perf profiling to each parser
Browse files Browse the repository at this point in the history
  • Loading branch information
quantizor committed Jul 10, 2018
1 parent 0ce2d88 commit 8cc1741
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1505,14 +1505,37 @@ export function compiler(markdown, options) {
},
};

// Object.keys(rules).forEach(key => {
// let parse = rules[key].parse;

// rules[key].parse = (...args) => {
// console.log(key, args[0]);
// return parse(...args);
// };
// });
Object.keys(rules).forEach(key => {
let { match, parse } = rules[key];

rules[key].match = (...args) => {
const start = performance.now();
const result = match(...args);
const delta = performance.now() - start;

if (delta > 5)
console.warn(
`Slow match for ${key}: ${delta.toFixed(3)}ms, input: ${
args[0]
}`
);

return result;
};

rules[key].parse = (...args) => {
const start = performance.now();
const result = parse(...args);
const delta = performance.now() - start;

if (delta > 5)
console.warn(`Slow parse for ${key}: ${delta.toFixed(3)}ms`);

console.log(`${key}:parse`, `${delta.toFixed(3)}ms`, args[0]);

return result;
};
});

const parser = parserFor(rules);
const emitter = reactFor(ruleOutput(rules));
Expand Down

0 comments on commit 8cc1741

Please sign in to comment.