From a6273b83b103c463937936ef2404575758a7baa4 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Wed, 15 Jun 2022 05:43:48 +0530 Subject: [PATCH] feat: account for rule creation time in performance reports (#15982) * feat: account for rule creation time in performance reports * docs: update info about per-rule performance * Revert "docs: update info about per-rule performance" This reverts commit 560b2807ff1288167fe89d95713a6e9e1c405498. * docs: update info about per-rule performance --- docs/src/developer-guide/working-with-rules.md | 2 +- lib/linter/linter.js | 2 +- lib/linter/timing.js | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) 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; }; }