Skip to content

Commit 63214a7

Browse files
committed
Add information about the new Performance report
Ref: PHPCSStandards/PHP_CodeSniffer#60
1 parent 8ce69d3 commit 63214a7

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

wiki/Reporting.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* [JSON](#printing-a-json-report)
1313
* [JUnit](#printing-a-junit-report)
1414
* Notify-Send
15+
* [Performance](#printing-a-performance-report)
1516
* [Source](#printing-a-source-report)
1617
* [SVN Blame](#printing-an-svn-blame-report)
1718
* [XML](#printing-an-xml-report)
@@ -441,6 +442,47 @@ PHP_CodeSniffer can output an XML report similar to the one produced by JUnit, a
441442
<p align="right"><a href="#table-of-contents">back to top</a></p>
442443

443444

445+
## Printing a Performance Report
446+
PHP_CodeSniffer can output a sniff performance report showing you which sniffs in the standard you use are _slowest_. This can be useful information to examine when a PHP_CodeSniffer run takes a long time to finish and will provide you with insights to share with the developers of the sniffs you use.
447+
448+
When the `--colors` option is enabled, sniffs which take more than twice the average run time per sniff will be displayed in orange and sniffs with a cumulative listener run time of more than three times the average run time per sniff will display in red.
449+
450+
> [!NOTE]
451+
> Enabling the performance report, in and of itself will make a PHP_CodeSniffer run slower. This is nothing to worry about as the exact time taken for each sniff isn't that relevant, it's the relative time taken _in comparison to other sniffs_ which is the interesting part.
452+
453+
> [!NOTE]
454+
> A sniff being "slow" can be due to the complexity of the sniff, in which case, this is to be expected.
455+
> Also keep in mind that the sniff run-time will often be influenced by whether or not the sniff finds errors in your code.
456+
457+
To print a performance report, use the `--report=performance` command line argument. The output will look like this:
458+
459+
$ phpcs --report=performance /path/to/code
460+
461+
PHP CODE SNIFFER SNIFF PERFORMANCE REPORT
462+
--------------------------------------------------------------------------------
463+
SNIFF TIME TAKEN (SECS) (%)
464+
--------------------------------------------------------------------------------
465+
Generic.NamingConventions.UpperCaseConstantName 0.074654 ( 44.6 %)
466+
PSR1.Files.SideEffects 0.028242 ( 16.9 %)
467+
PSR1.Methods.CamelCapsMethodName 0.027005 ( 16.2 %)
468+
PSR1.Classes.ClassDeclaration 0.021653 ( 13.0 %)
469+
Squiz.Classes.ValidClassName 0.010412 ( 6.2 %)
470+
Generic.PHP.DisallowAlternativePHPTags 0.002662 ( 1.6 %)
471+
Generic.PHP.DisallowShortOpenTag 0.002560 ( 1.5 %)
472+
Generic.Files.ByteOrderMark 0.000012 ( 0.0 %)
473+
--------------------------------------------------------------------------------
474+
TOTAL SNIFF PROCESSING TIME 0.167201 (100.0 %)
475+
476+
--------------------------------------------------------------------------------
477+
Time taken by sniffs 0.167201 ( 1.2 %)
478+
Time taken by PHPCS runner 13.336752 ( 98.8 %)
479+
--------------------------------------------------------------------------------
480+
TOTAL RUN TIME 13.503953 (100.0 %)
481+
--------------------------------------------------------------------------------
482+
483+
<p align="right"><a href="#table-of-contents">back to top</a></p>
484+
485+
444486
## Printing an SVN Blame Report
445487
Like the Git Blame report, PHP_CodeSniffer can make use of the `svn blame` command to try and determine who committed each error and warning to an SVN repository. To print an SVN Blame report, use the `--report=svnblame` command line argument. The output and options are the same as those described in the [Git Blame report](#printing-a-git-blame-report).
446488

wiki/Usage.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ Usage: phpcs [-nwlsaepqvi] [-d key[=value]] [--colors] [--no-colors]
6767
<processes> How many files should be checked simultaneously (default is 1)
6868
<report> Print either the "full", "xml", "checkstyle", "csv"
6969
"json", "junit", "emacs", "source", "summary", "diff"
70-
"svnblame", "gitblame", "hgblame" or "notifysend" report,
71-
or specify the path to a custom report class
70+
"svnblame", "gitblame", "hgblame", "notifysend" or "performance"
71+
report, or specify the path to a custom report class
7272
(the "full" report is printed by default)
7373
<reportFile> Write the report to the specified file path
7474
<reportWidth> How many columns wide screen reports should be printed

0 commit comments

Comments
 (0)