diff --git a/docs/src/developer-guide/working-with-rules.md b/docs/src/developer-guide/working-with-rules.md index d13e921daa8..248dc960ca7 100644 --- a/docs/src/developer-guide/working-with-rules.md +++ b/docs/src/developer-guide/working-with-rules.md @@ -732,7 +732,7 @@ Performance budget ok: 1443.736547ms (limit: 3409.090909090909ms) ### Per-rule Performance -ESLint has a built-in method to track performance of individual rules. Setting the `TIMING` environment variable will trigger the display, upon linting completion, of the ten longest-running rules, along with their individual running time and relative performance impact as a percentage of total rule processing time. +ESLint has a built-in method to track performance of individual rules. Setting the `TIMING` environment variable will trigger the display, upon linting completion, of the ten longest-running rules, along with their individual running time (rule creation + rule execution) and relative performance impact as a percentage of total rule processing time (rule creation + rule execution). ```bash $ TIMING=1 eslint lib diff --git a/lib/linter/linter.js b/lib/linter/linter.js index 5304a612a59..bd1bbb7ca82 100644 --- a/lib/linter/linter.js +++ b/lib/linter/linter.js @@ -1101,7 +1101,7 @@ function runRules(sourceCode, configuredRules, ruleMapper, parserName, languageO ) ); - const ruleListeners = createRuleListeners(rule, ruleContext); + const ruleListeners = timing.enabled ? timing.time(ruleId, createRuleListeners)(rule, ruleContext) : createRuleListeners(rule, ruleContext); /** * Include `ruleId` in error logs diff --git a/lib/linter/timing.js b/lib/linter/timing.js index c9ab01ec649..914cbf05591 100644 --- a/lib/linter/timing.js +++ b/lib/linter/timing.js @@ -138,10 +138,11 @@ module.exports = (function() { return function(...args) { let t = process.hrtime(); + const result = fn(...args); - fn(...args); t = process.hrtime(t); data[key] += t[0] * 1e3 + t[1] / 1e6; + return result; }; }