Skip to content

Commit

Permalink
perf: Add performance metrics in Rule.runChecks (#701)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish authored and WilcoFiers committed Jan 31, 2018
1 parent 752d16c commit 27fdc2f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/core/base/rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,11 @@ Rule.prototype.runChecks = function (type, node, options, resolve, reject) {
* @param {Function} callback Function to call when evaluate is complete; receives a RuleResult instance
*/
Rule.prototype.run = function (context, options, resolve, reject) {
//jshint maxstatements: 17
const q = axe.utils.queue();
const ruleResult = new RuleResult(this);
const markStart = 'mark_runchecks_start_' + this.id;
const markEnd = 'mark_runchecks_end_' + this.id;
let nodes;

try {
Expand All @@ -143,6 +146,7 @@ Rule.prototype.run = function (context, options, resolve, reject) {

if (options.performanceTimer) {
axe.log('gather (', nodes.length, '):', axe.utils.performanceTimer.timeElapsed()+'ms');
axe.utils.performanceTimer.mark(markStart);
}

nodes.forEach(node => {
Expand Down Expand Up @@ -180,6 +184,11 @@ Rule.prototype.run = function (context, options, resolve, reject) {
});
});

if (options.performanceTimer) {
axe.utils.performanceTimer.mark(markEnd);
axe.utils.performanceTimer.measure('runchecks_' + this.id, markStart, markEnd);
}

q.then(() => resolve(ruleResult))
.catch(error => reject(error));
};
Expand Down

0 comments on commit 27fdc2f

Please sign in to comment.